Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2022-04-29 08:11:02 +02:00
13 changed files with 276 additions and 40 deletions

View File

@@ -70,6 +70,30 @@ public class ItemManager implements ItemProvider
}
}
public void link()
{
for (ItemDefinition oc : items.values())
{
link(oc);
}
}
private void link(ItemDefinition item)
{
if (item.notedTemplate != -1)
{
item.linkNote(getItem(item.notedTemplate), getItem(item.notedID));
}
if (item.boughtTemplateId != -1)
{
item.linkBought(getItem(item.boughtTemplateId), getItem(item.boughtId));
}
if (item.placeholderTemplateId != -1)
{
item.linkPlaceholder(getItem(item.placeholderTemplateId), getItem(item.placeholderId));
}
}
public Collection<ItemDefinition> getItems()
{
return Collections.unmodifiableCollection(items.values());

View File

@@ -60,19 +60,13 @@ public class ItemDefinition
public int ambient;
public int contrast;
public int[] countCo;
public int[] countObj;
public String[] options = new String[]
{
null, null, "Take", null, null
};
public String[] interfaceOptions = new String[]
{
null, null, null, null, "Drop"
};
public String[] options = new String[]{null, null, "Take", null, null};
public String[] interfaceOptions = new String[]{null, null, null, null, "Drop"};
public int maleModel0 = -1;
public int maleModel1 = -1;
@@ -87,7 +81,7 @@ public class ItemDefinition
public int femaleOffset;
public int femaleHeadModel = -1;
public int femaleHeadModel2 = -1;
public int category;
public int notedID = -1;
@@ -99,13 +93,13 @@ public class ItemDefinition
public int boughtId = -1;
public int boughtTemplateId = -1;
public int placeholderId = -1;
public int placeholderTemplateId = -1;
public Map<Integer, Object> params = null;
public void updateNote(ItemDefinition notedItem, ItemDefinition unnotedItem)
public void linkNote(ItemDefinition notedItem, ItemDefinition unnotedItem)
{
this.inventoryModel = notedItem.inventoryModel;
this.zoom2d = notedItem.zoom2d;
@@ -123,4 +117,65 @@ public class ItemDefinition
this.cost = unnotedItem.cost;
this.stackable = 1;
}
public void linkBought(ItemDefinition var1, ItemDefinition var2)
{
this.inventoryModel = var1.inventoryModel;
this.zoom2d = var1.zoom2d;
this.xan2d = var1.xan2d;
this.yan2d = var1.yan2d;
this.zan2d = var1.zan2d;
this.xOffset2d = var1.xOffset2d;
this.yOffset2d = var1.yOffset2d;
this.colorFind = var2.colorFind;
this.colorReplace = var2.colorReplace;
this.textureFind = var2.textureFind;
this.textureReplace = var2.textureReplace;
this.name = var2.name;
this.members = var2.members;
this.stackable = var2.stackable;
this.maleModel0 = var2.maleModel0;
this.maleModel1 = var2.maleModel1;
this.maleModel2 = var2.maleModel2;
this.femaleModel0 = var2.femaleModel0;
this.femaleModel1 = var2.femaleModel1;
this.femaleModel2 = var2.femaleModel2;
this.maleHeadModel = var2.maleHeadModel;
this.maleHeadModel2 = var2.maleHeadModel2;
this.femaleHeadModel = var2.femaleHeadModel;
this.femaleHeadModel2 = var2.femaleHeadModel2;
this.team = var2.team;
this.options = var2.options;
this.interfaceOptions = new String[5];
if (var2.interfaceOptions != null)
{
for (int var3 = 0; var3 < 4; ++var3)
{
this.interfaceOptions[var3] = var2.interfaceOptions[var3];
}
}
this.interfaceOptions[4] = "Discard";
this.cost = 0;
}
public void linkPlaceholder(ItemDefinition var1, ItemDefinition var2)
{
this.inventoryModel = var1.inventoryModel;
this.zoom2d = var1.zoom2d;
this.xan2d = var1.xan2d;
this.yan2d = var1.yan2d;
this.zan2d = var1.zan2d;
this.xOffset2d = var1.xOffset2d;
this.yOffset2d = var1.yOffset2d;
this.colorFind = var1.colorFind;
this.colorReplace = var1.colorReplace;
this.textureFind = var1.textureFind;
this.textureReplace = var1.textureReplace;
this.stackable = var1.stackable;
this.name = var2.name;
this.cost = 0;
this.members = false;
this.isTradeable = false;
}
}

View File

@@ -72,11 +72,6 @@ public class ItemSpriteFactory
}
}
if (item.notedTemplate != -1)
{
item.updateNote(itemProvider.provide(item.notedTemplate), itemProvider.provide(item.notedID));
}
Model itemModel = getModel(modelProvider, item);
if (itemModel == null)
{
@@ -96,7 +91,11 @@ public class ItemSpriteFactory
else if (item.boughtTemplateId != -1)
{
auxSpritePixels = createSpritePixels(itemProvider, modelProvider, spriteProvider, textureProvider,
<<<<<<< HEAD
item.boughtId, quantity, border, shadowColor, false);
=======
item.boughtId, quantity, border, 0, false);
>>>>>>> runelite/master
if (auxSpritePixels == null)
{
return null;

View File

@@ -69,13 +69,16 @@ public class RSTextureProvider
TextureDefinition var2 = this.textures[var1];
if (var2 != null)
{
if (var2.pixels != null)
synchronized (var2)
{
if (var2.pixels != null)
{
return var2.pixels;
}
var2.method2680(this.brightness, this.width, spriteProvider);
return var2.pixels;
}
boolean var3 = var2.method2680(this.brightness, this.width, spriteProvider);
return var2.pixels;
}
return null;

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.cache.item;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import lombok.extern.slf4j.Slf4j;
import net.runelite.cache.IndexType;
import net.runelite.cache.ItemManager;
import net.runelite.cache.SpriteManager;
import net.runelite.cache.StoreLocation;
import net.runelite.cache.TextureManager;
import net.runelite.cache.definitions.ItemDefinition;
import net.runelite.cache.definitions.ModelDefinition;
import net.runelite.cache.definitions.loaders.ModelLoader;
import net.runelite.cache.definitions.providers.ModelProvider;
import net.runelite.cache.fs.Archive;
import net.runelite.cache.fs.Index;
import net.runelite.cache.fs.Store;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@Slf4j
public class ItemSpriteFactoryTest
{
@Rule
public TemporaryFolder folder = StoreLocation.getTemporaryFolder();
@Test
@Ignore
public void test() throws IOException
{
File base = StoreLocation.LOCATION,
outDir = folder.newFolder();
int count = 0;
try (Store store = new Store(base))
{
store.load();
ItemManager itemManager = new ItemManager(store);
itemManager.load();
itemManager.link();
ModelProvider modelProvider = new ModelProvider()
{
@Override
public ModelDefinition provide(int modelId) throws IOException
{
Index models = store.getIndex(IndexType.MODELS);
Archive archive = models.getArchive(modelId);
byte[] data = archive.decompress(store.getStorage().loadArchive(archive));
ModelDefinition inventoryModel = new ModelLoader().load(modelId, data);
return inventoryModel;
}
};
SpriteManager spriteManager = new SpriteManager(store);
spriteManager.load();
TextureManager textureManager = new TextureManager(store);
textureManager.load();
for (ItemDefinition itemDef : itemManager.getItems())
{
if (itemDef.name == null || itemDef.name.equalsIgnoreCase("null"))
{
continue;
}
try
{
BufferedImage sprite = ItemSpriteFactory.createSprite(itemManager, modelProvider, spriteManager, textureManager,
itemDef.id, 1, 1, 3153952, false);
File out = new File(outDir, itemDef.id + ".png");
BufferedImage img = sprite;
ImageIO.write(img, "PNG", out);
++count;
}
catch (Exception ex)
{
log.warn("error dumping item {}", itemDef.id, ex);
}
}
}
log.info("Dumped {} item images to {}", count, outDir);
}
}