Skip to content

Commit a1d93c3

Browse files
committed
Add ChunkRemesh and ChunkRemeshed
1 parent 3f17cfa commit a1d93c3

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

CubeModLoader/GenericMod.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class GenericMod {
6969

7070
Priority OnCreatureManaGenerationCalculatedPriority = NormalPriority;
7171
virtual void OnCreatureManaGenerationCalculated(void* creature, float* manaGeneration) {}
72+
73+
Priority OnChunkRemeshPriority = NormalPriority;
74+
virtual void OnChunkRemesh(void* zone) {}
75+
76+
Priority OnChunkRemeshedPriority = NormalPriority;
77+
virtual void OnChunkRemeshed(void* zone) {}
7278
};
7379

7480
#endif // GENERICMOD_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extern "C" int ChunkRemeshHandler(void* zone) {
2+
for (uint8_t priority = 0; priority <= 4; priority += 1) {
3+
for (DLL* dll : modDLLs) {
4+
if (dll->mod->OnChunkRemeshPriority == (GenericMod::Priority)priority) {
5+
dll->mod->OnChunkRemesh(zone);
6+
}
7+
}
8+
}
9+
return 0;
10+
}
11+
12+
GETTER_VAR(void*, ASM_ChunkRemeshHandler_jmpback);
13+
void ASM_ChunkRemeshHandler() {
14+
asm(".intel_syntax \n"
15+
PUSH_ALL
16+
17+
PREPARE_STACK
18+
19+
"mov rcx, r13 \n"
20+
"call ChunkRemeshHandler \n"
21+
22+
RESTORE_STACK
23+
24+
25+
POP_ALL
26+
27+
// original code
28+
"lea ebx, [r14+0x40] \n"
29+
"mov [rbp-0x54], ebx \n"
30+
"lea edi, [r15+0x40] \n"
31+
"mov [rbp-0x64], edi \n"
32+
33+
DEREF_JMP(ASM_ChunkRemeshHandler_jmpback)
34+
);
35+
}
36+
void SetupChunkRemeshHandler() {
37+
WriteFarJMP(Offset(base, 0xE969C), (void*)&ASM_ChunkRemeshHandler);
38+
ASM_ChunkRemeshHandler_jmpback = Offset(base, 0xE96AA);
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extern "C" int ChunkRemeshedHandler(void* zone) {
2+
for (uint8_t priority = 0; priority <= 4; priority += 1) {
3+
for (DLL* dll : modDLLs) {
4+
if (dll->mod->OnChunkRemeshedPriority == (GenericMod::Priority)priority) {
5+
dll->mod->OnChunkRemeshed(zone);
6+
}
7+
}
8+
}
9+
return 0;
10+
}
11+
12+
GETTER_VAR(void*, ASM_ChunkRemeshedHandler_jmpback);
13+
void ASM_ChunkRemeshedHandler() {
14+
asm(".intel_syntax \n"
15+
PUSH_ALL
16+
17+
PREPARE_STACK
18+
19+
"mov rcx, r8 \n"
20+
"call ChunkRemeshedHandler \n"
21+
22+
RESTORE_STACK
23+
24+
25+
POP_ALL
26+
27+
// original code
28+
"mov rdx, [rdi] \n"
29+
"mov [rdi], rdi \n"
30+
"mov rax, [rbp+0x20] \n"
31+
"mov [rax+8], rax \n"
32+
33+
DEREF_JMP(ASM_ChunkRemeshedHandler_jmpback)
34+
);
35+
}
36+
void SetupChunkRemeshedHandler() {
37+
WriteFarJMP(Offset(base, 0xECB5F), (void*)&ASM_ChunkRemeshedHandler);
38+
ASM_ChunkRemeshedHandler_jmpback = Offset(base, 0xECB6D);
39+
}

CubeModLoader/main.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "crc.h"
77
#include "mutex.h"
88

9-
#define MOD_MAJOR_VERSION 6
9+
#define MOD_MAJOR_VERSION 7
1010
#define MOD_MINOR_VERSION 1
1111

1212
#define CUBE_VERSION "1.0.0-1"
@@ -44,6 +44,8 @@ GETTER_VAR(void*, initterm_e); // A pointer to that function
4444
#include "callbacks/CreatureResistanceCalculatedHandler.h"
4545
#include "callbacks/CreatureRegenerationCalculatedHandler.h"
4646
#include "callbacks/CreatureManaGenerationCalculatedHandler.h"
47+
#include "callbacks/ChunkRemeshHandler.h"
48+
#include "callbacks/ChunkRemeshedHandler.h"
4749

4850
void SetupHandlers() {
4951
SetupChatHandler();
@@ -65,6 +67,8 @@ void SetupHandlers() {
6567
SetupCreatureResistanceCalculatedHandler();
6668
SetupCreatureRegenerationCalculatedHandler();
6769
SetupCreatureManaGenerationCalculatedHandler();
70+
SetupChunkRemeshHandler();
71+
SetupChunkRemeshedHandler();
6872
}
6973

7074

@@ -114,15 +118,21 @@ extern "C" void StartMods() {
114118
for (DLL* dll : modDLLs) {
115119
int majorVersion = ((int(*)())dll->ModMajorVersion)();
116120
int minorVersion = ((int(*)())dll->ModMinorVersion)();
117-
if (majorVersion != MOD_MAJOR_VERSION) {
118-
sprintf(msg, "%s has major version %d but requires %d.\n", dll->fileName.c_str(), majorVersion, MOD_MAJOR_VERSION);
121+
122+
if (majorVersion > MOD_MAJOR_VERSION) {
123+
sprintf(msg, "%s has major version %d but requires %d. You should update your mod loader.\n", dll->fileName.c_str(), majorVersion, MOD_MAJOR_VERSION);
119124
Popup("Error", msg);
120125
exit(1);
126+
}
121127

128+
if (majorVersion < MOD_MAJOR_VERSION) {
129+
sprintf(msg, "%s has major version %d but requires %d. The mod author needs to update this mod to CWSDK %d.X\n", dll->fileName.c_str(), majorVersion, MOD_MAJOR_VERSION, MOD_MAJOR_VERSION);
130+
Popup("Error", msg);
131+
exit(1);
122132
}
123133

124134
if (minorVersion > MOD_MINOR_VERSION) {
125-
sprintf(msg, "%s has minor version %d but requires %d or lower.\n", dll->fileName.c_str(), minorVersion, MOD_MINOR_VERSION);
135+
sprintf(msg, "%s has minor version %d but requires %d or lower. You should update your mod loader.\n", dll->fileName.c_str(), minorVersion, MOD_MINOR_VERSION);
126136
Popup("Error", msg);
127137
exit(1);
128138
}

0 commit comments

Comments
 (0)