2023-03-31 20:34:04 +02:00
|
|
|
from struct import pack
|
2023-03-31 18:52:22 +02:00
|
|
|
|
2023-03-31 21:58:07 +02:00
|
|
|
from hack import Hack
|
2023-04-04 11:14:10 +02:00
|
|
|
from utils import Color3i, errors_unload
|
2023-03-31 21:58:07 +02:00
|
|
|
|
2023-03-31 18:52:22 +02:00
|
|
|
|
|
|
|
class Chams(Hack):
|
2023-04-01 16:11:56 +02:00
|
|
|
def __init__(self, **kwargs) -> None:
|
|
|
|
super().__init__(**kwargs)
|
2023-03-31 18:52:22 +02:00
|
|
|
|
2023-05-05 16:04:06 +02:00
|
|
|
self.__color = (Color3i(255, 255, 0), 5.0)
|
2023-04-03 02:40:57 +02:00
|
|
|
self.__default_color = None
|
2023-03-31 21:58:07 +02:00
|
|
|
|
2023-03-31 18:52:22 +02:00
|
|
|
def chams(self) -> None:
|
|
|
|
# Aliases
|
|
|
|
mem = self.pm
|
|
|
|
offset = self.offsets
|
2023-04-03 02:40:57 +02:00
|
|
|
color = self.__color[0]
|
|
|
|
brightness = self.__color[1]
|
2023-03-31 18:52:22 +02:00
|
|
|
|
|
|
|
# Get module addresses
|
2023-04-03 02:40:57 +02:00
|
|
|
self.__client = self.find_module("client")
|
|
|
|
self.__engine = self.find_module("engine")
|
|
|
|
client = self.__client
|
|
|
|
engine = self.__engine
|
2023-03-31 18:52:22 +02:00
|
|
|
|
|
|
|
# Get local player
|
|
|
|
local_player = self.find_uint(client, offset["dwLocalPlayer"])
|
|
|
|
|
|
|
|
def cheat():
|
|
|
|
# Loop all entities
|
|
|
|
for i in range(1, 32): # 0 is world
|
2023-05-05 16:04:06 +02:00
|
|
|
entity = int(
|
|
|
|
mem.read_uint(
|
|
|
|
client + offset["dwEntityList"] + i * offset["entity_size"]
|
|
|
|
)
|
|
|
|
)
|
2023-03-31 18:52:22 +02:00
|
|
|
|
|
|
|
# Ignore if entity doesn't exist
|
|
|
|
if not entity:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Ignore allies
|
2023-05-05 16:04:06 +02:00
|
|
|
if mem.read_int(entity + offset["m_iTeamNum"]) == mem.read_int(
|
|
|
|
local_player + offset["m_iTeamNum"]
|
|
|
|
):
|
2023-03-31 18:52:22 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
# Space between values
|
2023-05-05 16:04:06 +02:00
|
|
|
i = (
|
|
|
|
int(mem.read_int(entity + offset["m_iGlowIndex"]))
|
|
|
|
* offset["glow_obj_size"]
|
|
|
|
)
|
2023-03-31 18:52:22 +02:00
|
|
|
|
2023-04-03 02:40:57 +02:00
|
|
|
if not self.__default_color:
|
|
|
|
self.__default_color = (
|
|
|
|
Color3i(
|
2023-05-05 16:04:06 +02:00
|
|
|
int(
|
|
|
|
mem.read_uint(
|
|
|
|
entity + offset["m_clrRender"] + offset["render_R"]
|
|
|
|
)
|
|
|
|
),
|
|
|
|
int(
|
|
|
|
mem.read_uint(
|
|
|
|
entity + offset["m_clrRender"] + offset["render_G"]
|
|
|
|
)
|
|
|
|
),
|
|
|
|
int(
|
|
|
|
mem.read_uint(
|
|
|
|
entity + offset["m_clrRender"] + offset["render_B"]
|
|
|
|
)
|
|
|
|
),
|
2023-04-03 02:40:57 +02:00
|
|
|
),
|
2023-05-05 16:04:06 +02:00
|
|
|
mem.read_int(engine + offset["model_ambient_min"]),
|
2023-04-03 02:40:57 +02:00
|
|
|
)
|
|
|
|
|
2023-03-31 18:52:22 +02:00
|
|
|
# Change color
|
2023-04-03 02:40:57 +02:00
|
|
|
if color.r > 0:
|
2023-03-31 21:58:07 +02:00
|
|
|
mem.write_uint(
|
2023-05-05 16:04:06 +02:00
|
|
|
entity + offset["m_clrRender"] + offset["render_R"], color.r
|
|
|
|
)
|
2023-04-03 02:40:57 +02:00
|
|
|
if color.g > 0:
|
2023-03-31 21:58:07 +02:00
|
|
|
mem.write_uint(
|
2023-05-05 16:04:06 +02:00
|
|
|
entity + offset["m_clrRender"] + offset["render_G"], color.g
|
|
|
|
)
|
2023-04-03 02:40:57 +02:00
|
|
|
if color.b > 0:
|
2023-03-31 21:58:07 +02:00
|
|
|
mem.write_uint(
|
2023-05-05 16:04:06 +02:00
|
|
|
entity + offset["m_clrRender"] + offset["render_B"], color.b
|
|
|
|
)
|
2023-03-31 20:34:04 +02:00
|
|
|
|
2023-04-01 16:20:46 +02:00
|
|
|
# Override the brightness of models by increasing
|
|
|
|
# the minimal brightness value
|
2023-03-31 20:34:04 +02:00
|
|
|
mem.write_int(
|
|
|
|
engine + offset["model_ambient_min"],
|
2023-05-05 16:04:06 +02:00
|
|
|
int.from_bytes(pack("f", brightness), byteorder="little")
|
|
|
|
^ (engine + offset["model_ambient_min"] - 0x2C),
|
2023-03-31 20:34:04 +02:00
|
|
|
)
|
2023-03-31 18:52:22 +02:00
|
|
|
|
|
|
|
self.hack_loop(cheat)
|
2023-04-03 02:40:57 +02:00
|
|
|
|
|
|
|
def chams_unload(self):
|
|
|
|
# Aliases
|
|
|
|
mem = self.pm
|
|
|
|
offset = self.offsets
|
2023-04-04 11:14:10 +02:00
|
|
|
try:
|
|
|
|
color = self.__default_color[0] # type: ignore
|
|
|
|
brightness = self.__default_color[1] # type: ignore
|
|
|
|
client = self.__client
|
|
|
|
engine = self.__engine
|
|
|
|
except errors_unload():
|
|
|
|
# No modification has been done
|
|
|
|
return
|
2023-04-03 02:40:57 +02:00
|
|
|
|
|
|
|
# Loop all entities
|
|
|
|
for i in range(1, 32): # 0 is world
|
2023-05-05 16:04:06 +02:00
|
|
|
entity = int(
|
|
|
|
mem.read_uint(
|
|
|
|
client + offset["dwEntityList"] + i * offset["entity_size"]
|
|
|
|
)
|
|
|
|
)
|
2023-04-03 02:40:57 +02:00
|
|
|
|
|
|
|
# Ignore if entity doesn't exist
|
|
|
|
if not entity:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Reset to default value if needed
|
|
|
|
if color.r > 0:
|
|
|
|
mem.write_uint(
|
2023-05-05 16:04:06 +02:00
|
|
|
entity + offset["m_clrRender"] + offset["render_R"], color.r
|
|
|
|
)
|
2023-04-03 02:40:57 +02:00
|
|
|
if color.g > 0:
|
|
|
|
mem.write_uint(
|
2023-05-05 16:04:06 +02:00
|
|
|
entity + offset["m_clrRender"] + offset["render_G"], color.g
|
|
|
|
)
|
2023-04-03 02:40:57 +02:00
|
|
|
if color.b > 0:
|
|
|
|
mem.write_uint(
|
2023-05-05 16:04:06 +02:00
|
|
|
entity + offset["m_clrRender"] + offset["render_B"], color.b
|
|
|
|
)
|
2023-04-03 02:40:57 +02:00
|
|
|
|
|
|
|
mem.write_int(engine + offset["model_ambient_min"], brightness)
|