[Python] CopyChat

Simple copychat with autoresponse​


Dictionary from which to find word
Code:
elements = {
  "Calcium": "Ca",
  "Hydrogen": "H",
  "Helium": "He"
}


most credits to a russian guy, russian are always crazy

Code:
import pymem, re, example

from pymem import Pymem


FUNC_SAMP_SENDSAY = 0x57F0

SAMP_FIRST_CHAT_MESSAGE_OFFSET = 0x152
SAMP_CHAT_MESSAGE_SIZE = 0xFC
ADDR_SAMP_CHATMSG_PTR = 0x21A0E4
SAMP_MAX_CHAT_MESSAGES = 99


class findproc:
    def __init__(self) -> None:
        self.process = Pymem("gta_sa.exe")
        self.module = pymem.process.module_from_name(
            self.process.process_handle, "samp.dll"
        ).lpBaseOfDll

    def close(self) -> None:
        self.process.close_process()




class API:
    def __init__(self, findproc: findproc) -> None:
        self.samp = samp

    def send_chat(self, message: str, encoding: str = "utf8") -> None:
        address = self.samp.process.allocate(len(message))
        self.samp.process.write_bytes(address, message.encode(encoding), len(message))
        self.samp.process.start_thread(self.samp.module + FUNC_SAMP_SENDSAY, address)
        self.samp.process.free(address)



    def read_chat(self, line: int = 0, encoding: str = "ISO-8859-1") -> str:
        address = self.samp.process.read_int(self.samp.module + ADDR_SAMP_CHATMSG_PTR)
        text = self.samp.process.read_bytes(
            address
            + SAMP_FIRST_CHAT_MESSAGE_OFFSET
            + (SAMP_MAX_CHAT_MESSAGES - line) * SAMP_CHAT_MESSAGE_SIZE,
            SAMP_CHAT_MESSAGE_SIZE,
        )
        return text.decode(encoding)




samp = findproc()
api = API(samp)


lastline = api.read_chat()

for word in example.elements:
    if word in lastline:
        print(example.elements[word])
        api.send_chat(example.elements[word])
        break

samp.close()

what i would point out is that lastline is returning many null characters and idk why, it may be because of the encoding in def read_chat(self, line: int = 0, encoding: str = "ISO-8859-1") -> str: but with utf8 it does not work so idk, if you have a solution i would love to see it

u can play with it by reversing the string or things like that
Code:
#Reversed String
return last_line[::-1]

#Remove digits
return re.sub(pattern=r"\d", repl=r"", string=last_line)

#Upper/Lower
return last_line.upper()
return last_line.lower()
 
Top