def update(self): self.prev_hp = self.hp self.hp = pm.float(self.ptr + 0x34) self.status = pm.int8(self.ptr + 0x4C) self.resource_amount = pm.float(self.ptr + 0x48) self.resource_type = Primitive.ResourceTable[pm.int8(self.ptr + 0x50)] self.position = pm.struct(self.ptr + 0x3c, "ff") self.selected = pm.int8(self.ptr + 0x3a)
def __init__(self, udata): super(Attack, self).__init__() self.range = pm.float(udata.ptr + 0x154) self.reload_time = pm.float(udata.ptr + 0x160) self.accurancy = pm.int16(udata.ptr + 0x166) self.displayed = pm.int16(udata.ptr + 0x17e) cnt = pm.int16(udata.ptr + 0x148) if cnt != 0: ptr = pm.pointer(udata.ptr + 0x14c) big_struct = pm.struct(ptr, "hh" * cnt) iterator = iter(big_struct) self.extend(zip(iterator, iterator))
def __init__(self, ptr, owner): super(UnitData, self).__init__() # Save the address self.ptr = ptr self.owner = owner # constants self.__name = None self.name_id = pm.int32(ptr + 0x8) self.icon = pm.int16(ptr + 0x54) self.max_hp = pm.int16(ptr + 0x2a) self.max_garrison = pm.int16(ptr + 0x30) # pointers self.id = pm.int16(ptr + 0x12) self.class_ = pm.int16(ptr + 0x16) self.superclass = pm.int16(ptr + 0x4) # But superclass is different for trebuchet in this script for reasons... if self.class_ in ClassData.trebuchets: self.superclass = SuperclassData.combatant self.armor = Armor(self) self.attack = Attack(self) self.costs = Costs(self) self.speed = 0.0 self.train_time = 0 if self.superclass in [ SuperclassData.building, SuperclassData.combatant ]: self.speed = pm.float(ptr + 0xe8) self.train_time = pm.int16(ptr + 0x19e)
def __init__(self, ptr, owner, udata): # ptr - pointer to the object # owner - Player datastructure who has this unit # udata - metadata, see `aoc_object_data.py` super(Primitive, self).__init__() self.ptr = ptr self.owner = owner self.udata = udata # Load data self.id = pm.int32(ptr + 0x8) # Game ID keeps unchanged, no need for update self.hp = pm.float(ptr + 0x34) self.selected = pm.int8(ptr + 0x3a) self.status = pm.int8(ptr + 0x4C) # Load consts self.idle = False self.idle_time = 0 self.idle_total_time = 0 self.busy_time = 0 self.busy_total_time = 0 self.garrison = [] self.research = None self.training = None self.position = None self.prev_hp = None self.queue = None self.construction = None self.group = 0 self.created_time = GTime.time self.resource_amount = 0 self.resource_type = ""
def update(self): for key in self.dictionary: self.dictionary[key].delete = True delete = [] for id in self.id_list: time = pm.float(self.ptr_times + 0x10 * id) total_time = pm.int16(self.ptr_researches + 0x54 * id + 0x26) icon = pm.int16(self.ptr_researches + 0x54 * id + 0x2C) cooldown = total_time - time if time == 0.0: delete.append(id) elif total_time > time: if id not in self.dictionary: self.dictionary[id] = Technology(self.owner, id, icon, time, total_time, cooldown) else: self.dictionary[id].update(self.owner, id, icon, time, total_time, cooldown) self.dictionary[id].delete = False else: self.done.append(Technology(self.owner, id, icon, GTime.time)) delete.append(id) for id in delete: self.id_list.remove(id) delete = [] for key in self.dictionary: if self.dictionary[key].delete: delete += [key] for key in delete: del self.dictionary[key] self.progression = list(self.dictionary.values())
def update(self): """ Fills the players list""" self.up = True ptr = pm.pointer(pm.base_address + 0x006EEFB4) ptr = pm.pointer(ptr + 0x0) ptr = pm.pointer(ptr + 0x60) ptr = pm.pointer(ptr + 0xCE4) if not ptr: # ptr is null if not in the lobby return False self.victory = Lobby.VICTORY_OPTIONS[pm.int32(ptr + 0x50)] self.victory_time_or_score = pm.int32(ptr + 0x54) # Time is in years! self.map_size = Lobby.MAP_SIZE_OPTIONS[pm.int32(ptr + 0x90)] self.reveal_map = Lobby.REVEAL_MAP_OPTIONS[pm.int32(ptr + 0x9c)] self.resources = Lobby.RESOURCES_OPTIONS[pm.int32(ptr + 0xa0)] self.starting_age = Lobby.STARTING_AGE_OPTIONS[pm.int32(ptr + 0xa4)] self.ending_age = Lobby.STARTING_AGE_OPTIONS[pm.int32(ptr + 0xa8)] self.game_speed = pm.float(ptr + 0x3b4 + 8 * 8) self.treaty_length = pm.int32(ptr + 0x3b8 + 8 * 8) self.population_limit = pm.int32(ptr + 0x3bC + 8 * 8) for i in range(Lobby.SKIP_GAIA, 9): p = ptr + 0x48 + 0x68 * i number = pm.int32(p + 0x50) # Get player number if number == -1: # A resets it self.players[i] = LobbyPlayer() else: # Update player's stuff player = self.players[i] player.number = number player.team = pm.int32(p + 0x0) player.deathmatch_rating = pm.int32(p + 0x44) player.rating = pm.int32(p + 0x48) player.color = pm.int32(p + 0x4C) player.name = pm.byte_string( pm.pointer(p + 0xC)) if i > 0 else b"Gaia" player.ai = False if player.name and player.name is not "Gaia" else True player.civ = None self.teams_together = not bool(pm.int8(ptr + 0x3c2 + 8 * 8)) self.all_techs = bool(pm.int8(ptr + 0x3c3 + 8 * 8)) self.lock_teams = bool(pm.int8(ptr + 0x3c5 + 8 * 8)) self.lock_speed = bool(pm.int8(ptr + 0x3c6 + 8 * 8)) self.record_game = bool(pm.int8(ptr + 0x3cc + 8 * 8)) self.allow_cheats = bool(pm.int8(ptr + 0x3cf + 8 * 8)) return True
def update(self): # Check if the game is running: 0 not running, 1 running pm.update() if not pm.int32(pm.base_address + 0x9E0708): self.running = False return False # Second check. try: ptr = pm.pointer( pm.base_address + 0x006FDA30 ) # three offsets are avaliable here: 006DC7F8, 006DDCA0, 006FDA30 each should point to the same address.. if not remove one You need to check for each address in record game. pm.pointer(ptr + 0x184) except NullAddress: self.running = False return False # Third check. Time if pm.int32(ptr + 0x68) <= 0: return False self.running = True # And get the common stuff GTime.set(pm.int32(ptr + 0x68)) self.screen_position = pm.struct(ptr + 0xD8, "ff") self.speed = pm.float(ptr + 0x16C) self.pov = self.players[pm.int8(ptr + 0x174) - 1] # Must be -1 if self.pov != self.player: if self.player is not None: self.player.pov = False self.player = self.pov # Set the new pov self.player.pov = True self.__update_teams__() market_price = pm.struct( ptr + 0x238, "fff" ) # Wood, food, stone coeficient see spirit of the law - markets Objects.selected.clear() Objects.selected_pointers.clear() # Update all players data for player in self.players: player.update(market_price) self.gaia.update(market_price) return True
def _check_construction_(self): time = pm.float(self.ptr + 0x250) # Sets the timer if the building HP has changed. time_delta = GTime.time_delta if time != self.constr_prev_time and time_delta > 0: # Tj hra bezi a zaroven self.timer = GTime.time # Calculates the timer if time == self.constr_prev_time and time_delta > 0: diff = GTime.time - self.timer if diff < Building.MAX_IDLE_CONSTRUCTION_TIME: time_delta = 0 if time == self.constr_prev_time and time_delta: # Did not change in time => return infinity return float("inf") elif time_delta: # Changed in time # Returns new value self.constr_prev_time = time return self.udata.train_time - time elif self.construction: # Returns previous value return self.construction
def create(self): try: # load id and time ptr = pm.pointer(self.building.ptr + 0x220) ptr = pm.pointer(ptr + 0x8) ptr = pm.pointer(ptr) self.id = pm.int16(ptr + 0x40) if self.id > 1402: return None time = pm.float(ptr + 0x44) # Load icon and total time ptr = self.building.owner.ptr ptr = pm.pointer(ptr + 0x14) ptr = pm.pointer(ptr + 0x4 * self.id) except NullAddress: return None self.icon = pm.int16(ptr + 0x54) self.total_time = pm.int16(ptr + 0x19e) self.time = 1 if isnan(time) else time self.cooldown = int(self.total_time - self.time) return self
def create(self): # some kind of constructor.. returns None if none research try: ptr = pm.pointer(self.building.ptr + 0x1f0) ptr = pm.pointer(ptr + 0x8) ptr = pm.pointer(ptr) self.id = pm.int16(ptr + 0x40) if self.id > 800: return None ptr = pm.pointer(self.building.owner.ptr + 0x1ae8) time = pm.float(pm.pointer(ptr) + 16 * self.id) ptr = pm.pointer(pm.pointer(ptr + 8)) except NullAddress: return None self.building.owner.research.add(self.id) self.total_time = pm.int16(ptr + 0x54 * self.id + 0x26) self.icon = pm.int16(ptr + 0x54 * self.id + 0x2C) self.time = self.total_time if isnan(time) else time # NaN occurs in the end of the research self.cooldown = int(self.total_time - self.time) # if ptr not in BuildingResearch.log[self.building.owner]: # BuildingResearch.log[self.building.owner].append(self) return self
def update(self): # Check if the game is running pm.update() if not pm.int32(pm.base_address + 0x9C8FB0): self.running = False return False # Second check. try: ptr = pm.pointer(pm.base_address + 0x006E62D8) pm.pointer(ptr + 0x184) except NullAddress: self.running = False return False # Third check. Time if pm.int32(ptr + 0x68) <= 0: return False self.running = True # And get the common stuff GTime.set(pm.int32(ptr + 0x68)) self.screen_position = pm.struct(ptr + 0xD8, "ff") self.speed = pm.float(ptr + 0x16C) self.pov = self.players[pm.int8(ptr + 0x174) - 1] # Must be -1 if self.pov != self.player: if self.player is not None: self.player.pov = False self.player = self.pov # Set the new pov self.player.pov = True self.__update_teams__() market_price = pm.struct( ptr + 0x238, "fff" ) # Wood, food, stone coeficient see spirit of the law - markets Objects.selected.clear() Objects.selected_pointers.clear() # Update all players data for player in self.players: player.update(market_price) self.gaia.update(market_price) return True