GameHacker's Toolkit

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
User avatar
SunBeam
Administration
Administration
Posts: 3197
Joined: Sun Feb 04, 2018 7:16 pm
Reputation: 1595

GameHacker's Toolkit

Post by SunBeam » Mon Jul 22, 2019 9:17 pm

Hello, Lua users.

Thought of an idea that might be (or not) something very useful to you/us. Been meaning to compile a library of Lua scripts that you can easily dump in main.lua and CE will be able to load it upon being started. That being said, you'd then be able to make use of those functions anytime during writing or executing of your own Lua. If you want to share such scripts with the community, please do so in this thread. Anything at all, useful for gamehacking.

I'll help compile the whole stuff into one giant Lua helper file :) Of course, you can keep as much as you want in/from it, as long as it won't clog CE to the point of not being able to open in a timely manner.

BR,
Sun

predprey
Fearless Donors
Fearless Donors
Posts: 174
Joined: Thu Mar 02, 2017 8:46 pm
Reputation: 109

Re: GameHacker's Toolkit

Post by predprey » Sat Jul 27, 2019 7:08 pm

I2 CE Lua Script Template Generator
https://forum.cheatengine.org/viewtopic.php?t=603424

Not the same thing but maybe a collaborative effort can serve to benefit both scripts since if we call the helper functions in our own scripts, we would also need to include the code of the helper functions into our table so users do not need to download the helper library as a dependency. Can't think of any helper functions that I use commonly though, most Lua scripts I write are specifically tailored for each game.

User avatar
TheyCallMeTim13
Administration
Administration
Posts: 1715
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 676

Re: GameHacker's Toolkit

Post by TheyCallMeTim13 » Wed Jan 01, 2020 2:29 am

I have one for AA scripts too. And in the lua one there's a function to "import" lua files that are stored as table files. But yeah, I tend to use a lot of lua. A teleporter, a table cea file module for external AA scripts to be added as table files when distributing the CT, a table updater, a logger, a module for saving and loading what scripts are enabled; and some general helper functions for auto attach, compact mode toggles, CE and game version checker. Just noticed this topic, so I'll try to post the most resent files. My Metal Gear Solid table is a good example with the most up to date files. But the teleporter and helper modules might make good additions.

EDIT:
Here's the modules I use. Includes I2CEHelpers, I2CETableCEA, I2CETableHelpers, I2CETeleporter, I2CETLogger, I2CETState, and I2CETUpdater.
TableLua.7z
Password: fearlessrevolution
(20.68 KiB) Downloaded 24 times
An example of the table lua script I use as a starter:

Code: Select all

--DEBUG = true

--RELEASE_MODE = true
COMPACT_MODE = RELEASE_MODE
DISABLE_HEADER_SORTING = true


PROCESS_NAME = 'mgsvtpp.exe'
TABLE_TITLE = 'mgsvtpp CET'
TABLE_NAME = 'mgsvtpp'
TABLE_VERSION = '5.0.3'
GAME_TITLE = 'Metal Gear Solid 5 The Phantom Pain'
-- GAME_FILE_VERSION = '1.0.15.1'
GAME_VERSION = '1.15'

VERSION_FILE_URL = 'https://docs.google.com/document/d/1pPgHNGV1-EmIpfxxXp0vnoeoZxlCg11ofdV1x78bJEw/export?format=txt'
AUTO_UPDATE = RELEASE_MODE

local requiredCEVersion = 6.83
-- local requiredCEVersionCloseOnFail = true
-- local requiredGameVersion = '1.0.15.1'
-- local requiredGameVersionCloseOnFail = true

function tableSetup()
	CETrequire('I2CETableCEA')
	CETrequire('I2CETeleporter')
	I2CETeleporter.AutoAllocate = false
	CETrequire('I2CETState')
	CETrequire('AddType_Int_Div2')
	CETrequire('AddType_Short_Div10')
   	CETrequire('AddType_GameTime')
	Logger.debugf('Table loaded: %s, %s', TABLE_TITLE, TABLE_VERSION)
	if RELEASE_MODE then
		--
		-- Release mode
	end
end

if MainForm == nil then
	MainForm = getMainForm()
end
if AddressList == nil then
	AddressList = getAddressList()
end

--------
-------- CE Table Require
--------
local tableLuaFilesDirectory = 'luaFiles'
local fileExt = '.lua'
function CETrequire(moduleStr)
	if moduleStr ~= nil then
		local localTableLuaFilePath = moduleStr
		if tableLuaFilesDirectory ~= nil and tableLuaFilesDirectory ~= '' then
			local sep = package.config:sub(1,1)
			localTableLuaFilePath = tableLuaFilesDirectory .. sep .. moduleStr
		end
		local f, err = io.open(localTableLuaFilePath .. fileExt)
		if f and not err then
			f:close()
			return dofile(localTableLuaFilePath .. fileExt)
		else
			local tableFile = findTableFile(moduleStr .. fileExt)
			if tableFile == nil then
				return nil
			end
			local stream = tableFile.getData()
			local fileStr = nil
			local bytes = stream.read(stream.Size)
			for i = 1, #bytes do
				if fileStr == nil then
					fileStr = ''
				end
				fileStr = fileStr .. string.char(bytes[i])
			end
			if fileStr then
				return loadstring(fileStr)()
			end
		end
	end
	return nil
end


--------
-------- Logger
--------
Logger = CETrequire('I2CETLogger')
Logger.LogName = 'CETlog'

--------
-------- Updater
--------
CETrequire('I2CETUpdater')
if AUTO_UPDATE then
	CETUpdater.TableVersion = TABLE_VERSION
	CETUpdater.TableName = TABLE_NAME
	CETUpdater.VersionFileUrl = VERSION_FILE_URL
	CETUpdater.checkTableVersion()
end

--------
-------- TableHelpers
--------
CETrequire('I2CETableHelpers')
I2CETableHelpers.init()

--------
-------- Auto Attach
--------
I2CETableHelpers.requireCEVersion(requiredCEVersion, requiredCEVersionCloseOnFail)
Logger.debugf('Useing CE version: %.1f', getCEVersion())

I2CETableHelpers.tableSetup = tableSetup
I2CETableHelpers.autoAttachCT(PROCESS_NAME, requiredGameVersion, requiredGameVersionCloseOnFail)

And a "Main Hooks" example that initializes the teleporter:

Code: Select all

{$lua}
if syntaxcheck then return end
I2CETableCEA.autoAssembleFile('PlayerHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('WaypointHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('SupplyDropCoordHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('VehicleHealthHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('PlayerVehicleCoordHook.CEA', MemRec)
-- I2CETableCEA.autoAssembleFile('SupplyDropCoordVehicleHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('SelectedMapIconCoordHook.CEA', MemRec)
----
I2CETableCEA.autoAssembleFile('DHorseCoordHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('DWalkerCoordHook.CEA', MemRec)
----
I2CETableCEA.autoAssembleFile('TimeHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('WeatherHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('AmmoHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('WeaponHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('SuppressorCapHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('BatteryMaxHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('ResourcesHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('ResourcesOnlineHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('ZoomHook.CEA', MemRec)
----
I2CETableCEA.autoAssembleFile('TankAmmoHook.CEA', MemRec)
I2CETableCEA.autoAssembleFile('DwHealthHook.CEA', MemRec)
------------------------------ ENABLE -------------------------------
[ENABLE]
I2CETeleporter.initMemory()
------------------------------ DISABLE ------------------------------
[DISABLE]

And then here is the call to auto generate the memory records for the teleportor:

Code: Select all

I2CETeleporter.generateMemoryRecords()
And here is an example of setting the bases and offsets for the teleportor:

Code: Select all

{$STRICT}

define(address, mgsvtpp.exe+9645D79)
define(bytes, 48 8B 41 38 48 8B 79 30)

////
//// ------------------------------ ENABLE ------------------------------
[ENABLE]
// aobScanModule(aobPlayerHook, mgsvtpp.exe, 48xxxxxx48xxxxxx4xxxxx4Cxxxxxx4Bxxxxxx4xxxxx49)
i2aobScanModule(aobPlayerHook, mgsvtpp.exe, 48xxxxxx48xxxxxx4xxxxx4Cxxxxxx4Bxxxxxx4xxxxx49)
define(injPlayerHook, aobPlayerHook)
// assert(injPlayerHook, bytes)
i2assert(injPlayerHook, bytes)
registerSymbol(injPlayerHook)

alloc(memPlayerHook, 0x400, injPlayerHook)

label(ptrPlayerHook)
registerSymbol(ptrPlayerHook)

label(n_code)
label(o_code)
label(exit)
label(return)

memPlayerHook:
	ptrPlayerHook:
		dq 0
	align 10 CC
	n_code:
		mov [ptrPlayerHook],rcx
	o_code:
		mov rax,[rcx+38]
		mov rdi,[rcx+30]
	exit:
		jmp return


////
//// ---------- Injection Point ----------
injPlayerHook:
	jmp n_code
	nop
	nop
	nop
	return:


{$lua}
I2CETeleporter.CoordPointerSymbol = '[[ptrPlayerHook]+30]+48'
I2CETeleporter.Xoffset = 0x20
I2CETeleporter.Yoffset = 0x24
I2CETeleporter.Zoffset = 0x28
I2CETeleporter.PlayerRotationAnglePointerSymbol = '[[ptrPlayerHook]+30]+48'
I2CETeleporter.PlayerYawOffset = 0x84
I2CETeleporter.CamRotationAnglePointerSymbol = '[[ptrPlayerHook]+38]+B8'
I2CETeleporter.CamPitchOffset = 0x270
I2CETeleporter.CamYawOffset = 0x274
I2CETeleporter.CamYawToPlayerYaw = function(cY) return (cY / 3) end
{$asm}

////
//// ------------------------------ DISABLE ------------------------------
[DISABLE]
////
//// ---------- Injection Point ----------
injPlayerHook:
	db bytes

unregisterSymbol(injPlayerHook)

unregisterSymbol(ptrPlayerHook)

dealloc(memPlayerHook)
And here's the latest Lua script generator, and AA script generator:
I2Plugins.7z
Password: fearlessrevolution
(29.02 KiB) Downloaded 29 times
CE wiki - Tutorials CE wiki - Auto Assembler Basics - CE wiki - Lua Basics If it's not a Personal Message don't PM me, use the forum. I ignore PMs that should be asked on the forum.

Post Reply

Who is online

Users browsing this forum: No registered users