Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
137 lines (102 loc) · 3.93 KB
/
Copy pathinit.lua
File metadata and controls
137 lines (102 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
local exports = {}
local function getAddress(aob, errorMsg, modifierFunc)
local address = core.AOBScan(aob, 0x400000)
if address == nil then
log(ERROR, errorMsg)
error("'gmResourceModifier' can not be initialized.")
end
if modifierFunc == nil then
return address;
end
return modifierFunc(address)
end
--[[ Main Func ]]--
exports.enable = function(self, moduleConfig, globalConfig)
--[[ get addresses ]]--
local placeToReplaceLoadGmsAddr = getAddress(
"e8 ? ? ? ff b9 ? ? ? 02 e8 ? ? ? ff 53 6a 03",
"'gmResourceModifier' was unable to find the gms loading call."
)
local actualLoadGmsAddress = getAddress(
"53 55 8b 6c 24 0c 56 57 8b d9",
"'gmResourceModifier' was unable to find the actual gms loading address."
)
local transformRGB555ToRGB565 = getAddress(
"55 8b ec 83 ec 0c 8b 45 08",
"'gmResourceModifier' was unable to find the RGB555 To RGB565 func address."
)
local gmImageHeaderAddr = getAddress(
"c1 e0 04 81 c1 ? ? ? 00 50 51",
"'gmResourceModifier' was unable to find the image header address.",
function(foundAddress) return core.readInteger(foundAddress + 5) end
)
local gmSizesAddr = getAddress(
"89 14 bd ? ? ? 00 eb 53",
"'gmResourceModifier' was unable to find the gm sizes address.",
function(foundAddress) return core.readInteger(foundAddress + 3) end
)
local gmOffsetAddr = getAddress(
"8b 2c bd ? ? ? 00 03 d7 3b fa",
"'gmResourceModifier' was unable to find the gm offset address.",
function(foundAddress) return core.readInteger(foundAddress + 3) end
)
local pixelFormatAddr = getAddress(
"81 3d ? ? ? 00 65 05 00 00 75 40",
"'gmResourceModifier' was unable to find the address of the pixel format.",
function(foundAddress) return core.readInteger(foundAddress + 2) end
)
--[[ load module ]]--
local requireTable = require("gmResourceModifier.dll") -- loads the dll in memory and runs luaopen_gmResourceModifier
-- no wrapping needed?
self.LoadGm1Resource = function(self, ...) return requireTable.lua_LoadGm1Resource(...) end
self.FreeGm1Resource = function(self, ...) return requireTable.lua_FreeGm1Resource(...) end
self.SetGm = function(self, ...) return requireTable.lua_SetGm(...) end
self.LoadResourceFromImage = function(self, ...) return requireTable.lua_LoadResourceFromImage(...) end
--[[ modify code ]]--
-- write the call to the own function
core.writeCode(
placeToReplaceLoadGmsAddr,
{0xE8, requireTable.funcAddress_DetouredLoadGmFiles - placeToReplaceLoadGmsAddr - 5} -- call to func
)
-- give actual load gms function
core.writeCode(
requireTable.address_ActualLoadGmsFunc,
{actualLoadGmsAddress}
)
-- give actual RGB transform function
core.writeCode(
requireTable.address_TransformTgxFromRGB555ToRGB565,
{transformRGB555ToRGB565}
)
-- give address of image header
core.writeCode(
requireTable.address_ShcImageHeaderStart,
{gmImageHeaderAddr}
)
-- give address of image sizes
core.writeCode(
requireTable.address_ShcSizesStart,
{gmSizesAddr}
)
-- give address of image offset
core.writeCode(
requireTable.address_ShcOffsetStart,
{gmOffsetAddr}
)
-- give address to pixel format
core.writeCode(
requireTable.address_GamePixelFormatAddr,
{pixelFormatAddr}
)
--[[ use config ]]--
-- none at the moment
--[[ test code ]]--
--local resId = self.LoadGm1Resource("ucp/resources/tile_castle.gm1")
--self.SetGm(0x34, -1, resId, -1)
--local resId = self.LoadGm1Resource("gm/tile_castle.gm1")
--self.SetGm(0x34, -1, resId, -1)
--local resId2 = self.LoadGm1Resource("gm/anim_windmill.gm1")
--self.SetGm(0x1a, -1, resId2, -1)
end
exports.disable = function(self, moduleConfig, globalConfig) error("not implemented") end
return exports