Skip to content

Commit

Permalink
Further memread optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablete1234 committed Jun 20, 2024
1 parent c41a768 commit 46b7f6d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AssemblyMediator extends Updatable implements AssemblyAPI {
private int selectedRecipeIndex;
private final Recipe selectedRecipe = new Recipe();

private boolean listUpdated = false;
private final FlashList<Recipe> recipes = FlashList.ofVector(Recipe::new);
private final List<Filter> filters = new ArrayList<>();
private final FlashList<RowFilter> rowSettings = FlashList.ofVector(RowFilter::new);
Expand All @@ -30,7 +31,7 @@ public void update() {
if (address == 0) return;
selectedRecipeIndex = readInt(0x48);

recipes.update(readAtom(0x60, 0x20));
listUpdated = false;
selectedRecipe.updateIfChanged(readAtom(0x70));
selectedRecipe.update();

Expand All @@ -46,6 +47,15 @@ public void update() {
isFilterDropDownOpen = readBoolean(0x78, 0x60, 0x1D0);
}

@Override
public List<? extends AssemblyAPI.Recipe> getRecipes() {
if (!listUpdated) {
recipes.update(readAtom(0x60, 0x20));
listUpdated = true;
}
return recipes;
}

@Getter
@ToString
private static class Recipe extends Updatable implements AssemblyAPI.Recipe {
Expand All @@ -64,6 +74,8 @@ private static class Recipe extends Updatable implements AssemblyAPI.Recipe {
public void update(long address) {
super.update(address);

recipeId = readString(0x58, 0x48);

rewardsArr.update(API.readAtom(address + 0x60));
rewards.clear();
rewardsArr.forEach(ptr -> rewards.add(API.readString(ptr, 0x48)));
Expand All @@ -76,10 +88,7 @@ public void update() {
isCraftable = readBoolean(0x20);
craftTimeLeft = (int) readDouble(0x40, 0x28, 0x38);

long recipe = readAtom(0x58);
recipeId = API.readString(recipe, 0x48);

long data = API.readAtom(recipe, 0x40, 0x20);
long data = readAtom(0x58, 0x40, 0x20);
visibility = API.readString(data, 0x90);
craftTimeData.update(API.readAtom(data, 0x98));
for (long i : craftTimeData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void update() {
}
}

public static class Booster extends Auto implements BoosterAPI.Booster {
public static class Booster extends Updatable implements BoosterAPI.Booster {
public double amount, cd;
public String category, name;

Expand All @@ -37,12 +37,17 @@ public static class Booster extends Auto implements BoosterAPI.Booster {
private final FlashListLong categoriesArr = FlashListLong.ofVector();

@Override
public void update() {
public void update(long address) {
super.update(address);
String oldCat = this.category;
this.category = readString(0x20);
if (!Objects.equals(this.category, oldCat))
this.cat = BoosterAPI.Type.of(category);
this.name = readString(0x40); //0x48 description;
}

@Override
public void update() {
this.amount = readDouble(0x50);
this.subBoostersArr.update(readLong(0x30));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public void update() {
availableRetrievers.update(API.readAtom(dispatchRetrieverData + 0x58));
inProgressRetrievers.update(API.readAtom(dispatchRetrieverData + 0x60));

selectedRetriever.update(API.readAtom(dispatchRetrieverData + 0x68));
selectedRetriever.updateIfChanged(API.readAtom(dispatchRetrieverData + 0x68));
selectedRetriever.update();
}

@Getter
@ToString
private static class Retriever extends Auto implements DispatchAPI.Retriever {
private static class Retriever extends Updatable implements DispatchAPI.Retriever {
private int id = -1, slotId = -1, tier = -1;
private String iconId = "", type = "", name = "", descriptionId = "";
private double duration = -1;
Expand All @@ -40,6 +41,22 @@ private static class Retriever extends Auto implements DispatchAPI.Retriever {
private final FlashList<Cost> costList = FlashList.ofVector(Cost::new);
private final Cost instantCost = new Cost();

@Override
public void update(long address) {
super.update(address);

long retrieverDefinition = readAtom(0x38);
this.id = API.readInt(retrieverDefinition, 0x20); // 1 to 18
this.tier = API.readInt(retrieverDefinition, 0x24); // 1, 2, 3, 4, 5 or 6
this.iconId = API.readString(retrieverDefinition, 0x30); // dispatch_retriever_r01
this.name = API.readString(retrieverDefinition, 0x38); // R-01
this.type = API.readString(retrieverDefinition, 0x40); // resource
this.descriptionId = API.readString(retrieverDefinition, 0x48); // dispatch_label_description_retriever_r01
this.costList.update(API.readAtom(retrieverDefinition, 0x50));

this.instantCost.update(API.readAtom(retrieverDefinition, 0x58));
}

@Override
public void update() {
if (address <= 0) return;
Expand All @@ -49,17 +66,6 @@ public void update() {
long dispatchModule = API.readAtom(address + 0x30);
this.slotId = API.readInt(dispatchModule + 0x20); // 0 for available, 1 to 5 for in-progress
this.duration = API.readDouble(dispatchModule + 0x28); // time left in seconds, or total time

long retrieverDefinition = API.readAtom(address + 0x38);
this.id = API.readInt(retrieverDefinition + 0x20); // 1 to 18
this.tier = API.readInt(retrieverDefinition + 0x24); // 1, 2, 3, 4, 5 or 6
this.iconId = API.readString(retrieverDefinition, 0x30); // dispatch_retriever_r01
this.name = API.readString(retrieverDefinition, 0x38); // R-01
this.type = API.readString(retrieverDefinition, 0x40); // resource
this.descriptionId = API.readString(retrieverDefinition, 0x48); // dispatch_label_description_retriever_r01
this.costList.update(API.readAtom(retrieverDefinition + 0x50));

this.instantCost.update(API.readAtom(retrieverDefinition + 0x58));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public void update() {
if (questDataAddr == 0) {
return;
}

dailyQuests.update(API.readAtom(questDataAddr + 0x60));
weeklyQuests.update(API.readAtom(questDataAddr + 0x68));
seassonQuests.update(API.readAtom(questDataAddr + 0x70));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static com.github.manolo8.darkbot.Main.API;

public class Item extends Updatable.Auto implements eu.darkbot.api.game.items.Item {
public class Item extends Updatable implements eu.darkbot.api.game.items.Item {
private static final int START = 36, END = 128 + 8;
private static final byte[] BUFFER = new byte[END - START];

Expand Down Expand Up @@ -53,6 +53,25 @@ private Set<Integer> getShortcutSet(SlotBarsProxy.Type type) {
return this.associatedSlots.computeIfAbsent(type, l -> new HashSet<>());
}

@Override
public void update(long address) {
super.update(address);
this.id = API.readString(address, 64);
this.counterType = API.readString(address, 72);
this.actionStyle = API.readString(address, 80);
this.iconLootId = API.readString(address, 96);

if (itemCategory != null) {
this.selectableItem = SelectableItem.ALL_ITEMS.get(itemCategory).stream()
.filter(i -> i.getId().equals(id))
.findFirst()
.orElse(null);

if (selectableItem != null && itemsMap != null)
itemsMap.put(selectableItem, this);
}
}

// TODO: 28.08.2022 Sometimes, after reload *some* items are probably invalid? Why?
@Override
public void update() {
Expand All @@ -74,27 +93,6 @@ public void update() {
this.itemTimer.update();
}

@Override
public void update(long address) {
if (this.address != address) {
this.id = API.readString(address, 64);
this.counterType = API.readString(address, 72);
this.actionStyle = API.readString(address, 80);
this.iconLootId = API.readString(address, 96);

if (itemCategory != null) {
this.selectableItem = SelectableItem.ALL_ITEMS.get(itemCategory).stream()
.filter(i -> i.getId().equals(id))
.findFirst()
.orElse(null);

if (selectableItem != null && itemsMap != null)
itemsMap.put(selectableItem, this);
}
}
super.update(address);
}

public boolean hasShortcut() {
return getSlotBarType() != null;
}
Expand Down

0 comments on commit 46b7f6d

Please sign in to comment.