Skip to content

Commit 4fe9b88

Browse files
committed
Initial commit.
0 parents  commit 4fe9b88

File tree

8 files changed

+270
-0
lines changed

8 files changed

+270
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
config.mk
2+
3+
*.o
4+
5+
*.dll
6+
!cncnet5.dll

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-include config.mk
2+
3+
OUTPUT = rename.dll
4+
CFLAGS = -std=c99 -Iinc/
5+
DLL_LDFLAGS = -mdll -Wl,--enable-stdcall-fixup
6+
7+
OBJS = src/rename.o src/ares.o
8+
9+
CC ?= gcc
10+
STRIP ?= strip
11+
RM ?= rm
12+
13+
.PHONY: default
14+
default: $(OUTPUT)
15+
16+
.PHONY: all
17+
all: rename.dll
18+
19+
$(OUTPUT): $(OBJS)
20+
$(CC) $(CFLAGS) $(DLL_LDFLAGS) -o $@ $^ -lmsvcrt
21+
$(STRIP) $@
22+
clean:
23+
$(RM) $(OUTPUT) $(OBJS)

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CnCNet for Ares
2+
================================================================================
3+
4+
Spawns Yuri's Revenge and connects players through cncnet5. This project should be used in conjunction with the [xna-cncnet-client](https://github.com/CnCNet/xna-cncnet-client) and [Ares](https://launchpad.net/ares/+download)
5+
6+
### Usage
7+
- Place cncnet5.dll in you mod folder with the xna-cncncet-client and the Ares files.
8+
- Optionally place rename.dll in the mod directory.
9+
- Syringe from Ares will automatically detect and include cncnet5.dll.
10+
- Configure xna-cncnet-client to execute Syringe.exe rather than game(md).exe
11+
12+
### Building
13+
- Download cncnet-for-ares
14+
- Edit src/rename.c, change the strings for the Gane name and file locations. Do not exceed the size of the existing strings in the game.
15+
- Download [win-builds](https://downloads.cncnet.org/win-builds-for-patching.zip) and install it by double clicking win-install.bat
16+
- In the cncnet5-for-ares run build.cmd by double clicking on it. Read the output window any errors you may introduced.
17+
- You should now have rename.dll. Now you can rename rename.dll to something appropriate for your mod (the name will not stop it from being loaded by Syringe).
18+
19+
20+
### Caveats
21+
- Source code for cncnet5.dll is not public, only the cncnet5.dll file is provided here.
22+
- You do not need to use the command line -SPAWN argument.
23+
- You may need to edit build.cmd if win-builds did not get installed into C:\win-builds-patch-32\

build.cmd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
REM
3+
REM cnc-patch environment config
4+
REM
5+
set PATH=C:\win-builds-patch-32\bin
6+
gmake clean
7+
pause
8+
gmake all
9+
pause

cncnet5.dll

29.5 KB
Binary file not shown.

inc/patch.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2013, 2014, 2020 Toni Spets <toni.spets@iki.fi>
3+
* Daniel Keeton Jr <dakeeton@gmail.com>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
#define CLEAR(start, value, end) \
19+
__asm ( \
20+
".section .patch,\"d0\";" \
21+
".long " #start ";" \
22+
".long " #end "-" #start ";" \
23+
".fill " #end "-" #start ", 1, " #value ";" \
24+
)
25+
26+
#define LJMP(src, dst) \
27+
__asm ( \
28+
".section .patch,\"d0\";" \
29+
".long " #src ";" \
30+
".long 5;" \
31+
".byte 0xE9;" \
32+
".long " #dst "-" #src " - 5;" \
33+
)
34+
35+
#define CALL(src, dst) \
36+
__asm ( \
37+
".section .patch,\"d0\";" \
38+
".long " #src ";" \
39+
".long 5;" \
40+
".byte 0xE8;" \
41+
".long " #dst "-" #src " - 5;" \
42+
)
43+
44+
#define SETDWORD(dst, value) \
45+
__asm ( \
46+
".section .patch,\"d0\";" \
47+
".long " #dst ";" \
48+
".long 4;" \
49+
".long " #value ";" \
50+
)
51+
52+
#define SETSTRING(dst, value) \
53+
__asm ( \
54+
".section .patch,\"d0\";" \
55+
".long " #dst ";" \
56+
".long (_memcpy_end_" #dst \
57+
" - _memcpy_start_" #dst ");" \
58+
"_memcpy_start_" #dst ":;" \
59+
".asciz " #value ";" \
60+
"_memcpy_end_" #dst ":;" \
61+
)

src/ares.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2013, 2014 Toni Spets <toni.spets@iki.fi>
3+
*
4+
* Permission to use, copy, modify, and distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#include <windows.h>
18+
#include <stdio.h>
19+
20+
// this tricks syringe to load this dll
21+
__asm (
22+
".section .syhks00,\"d8\";" // AlexB said the alignment has to be 16 bytes
23+
".long 0;"
24+
".long 0;"
25+
".string \"stub\";"
26+
);
27+
28+
#ifdef WWDEBUG
29+
#define dprintf printf
30+
#else
31+
#define dprintf(fmt, ...)
32+
#endif
33+
34+
static DWORD get_dword(char **p)
35+
{
36+
DWORD ret = *(DWORD *)*p;
37+
*p += sizeof(DWORD);
38+
return ret;
39+
}
40+
41+
BOOL WINAPI __declspec(dllexport)
42+
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
43+
{
44+
if (fdwReason == DLL_PROCESS_ATTACH)
45+
{
46+
char buf[MAX_PATH + 1] = { 0 };
47+
GetModuleFileName(NULL, buf, sizeof buf);
48+
49+
dprintf("Patching CnCNet 5 to %s\n", buf);
50+
51+
PIMAGE_DOS_HEADER dos_hdr = (void *)hinstDLL;
52+
PIMAGE_NT_HEADERS nt_hdr = (void *)((char *)hinstDLL + dos_hdr->e_lfanew);
53+
54+
char *patch = NULL;
55+
int patch_len = 0;
56+
57+
for (int i = 0; i < nt_hdr->FileHeader.NumberOfSections; i++)
58+
{
59+
PIMAGE_SECTION_HEADER sct_hdr = IMAGE_FIRST_SECTION(nt_hdr) + i;
60+
61+
if (strcmp(".patch", (char *)sct_hdr->Name) == 0)
62+
{
63+
patch = (char *)((char *)hinstDLL + sct_hdr->VirtualAddress);
64+
patch_len = sct_hdr->Misc.VirtualSize;
65+
break;
66+
}
67+
68+
sct_hdr++;
69+
}
70+
71+
dprintf("Found .patch @ %p (%d bytes)\n", patch, patch_len);
72+
73+
if (patch)
74+
{
75+
for (char *p = patch; p < patch + patch_len;)
76+
{
77+
DWORD paddress = get_dword(&p);
78+
if (paddress == 0) break;
79+
80+
DWORD plength = get_dword(&p);
81+
82+
dprintf("PATCH %8u bytes -> %8X\n", (unsigned int)plength, (unsigned int)paddress);
83+
DWORD protect = 0;
84+
VirtualProtect((void *)paddress, plength, PAGE_EXECUTE_READWRITE, &protect);
85+
memcpy((void *)paddress, p, plength);
86+
VirtualProtect((void *)paddress, plength, protect, NULL);
87+
88+
p += plength;
89+
}
90+
}
91+
}
92+
93+
return TRUE;
94+
}

src/rename.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2020 Daniel Keeton Jr <dakeeton@gmail.com>
3+
*
4+
* Permission to use, copy, modify, and distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#include "patch.h"
18+
19+
/*
20+
* Change the following strings
21+
* Do not make your new strings longer than the original strings.
22+
* Use the line of ); as a guide, if they aren't all lined up
23+
* then your new string isn't the correct length.
24+
*/
25+
26+
SETSTRING( 0x00849F48, "Yuri's Revenge" );
27+
SETSTRING( 0x0082668C, "EXPANDMD%02d.MIX" );
28+
SETSTRING( 0x0082621C, "AIMD.INI" );
29+
SETSTRING( 0x00826254, "ARTMD.INI" );
30+
SETSTRING( 0x00826198, "BATTLEMD.INI" );
31+
SETSTRING( 0x008261A8, "BATTLEMD*.INI" );
32+
SETSTRING( 0x008295E8, "%sMD.INI" );
33+
SETSTRING( 0x00825DF0, "EVAMD.INI" );
34+
SETSTRING( 0x00830370, "MAPSELMD.INI" );
35+
SETSTRING( 0x00839724, "MISSIONMD.INI" );
36+
SETSTRING( 0x00826260, "RULESMD.INI" );
37+
SETSTRING( 0x0082626C, "RULEMD*.INI" );
38+
SETSTRING( 0x00825E50, "SOUNDMD.INI" );
39+
SETSTRING( 0x0081C24C, "THEMEMD.MIX" );
40+
SETSTRING( 0x00825D94, "THEMEMD.INI" );
41+
SETSTRING( 0x00826444, "RA2MD.INI" );
42+
SETSTRING( 0x00826614, "ELOCAL*.MIX" );
43+
SETSTRING( 0x00826620, "ECACHE*.MIX" );
44+
SETSTRING( 0x0081C284, "MULTIMD.MIX" );
45+
SETSTRING( 0x00826780, "MULTIMD.MIX" );
46+
SETSTRING( 0x0081C2EC, "MAPSMD%02d.MIX" );
47+
SETSTRING( 0x0082679C, "MAPSMD*.MIX" );
48+
SETSTRING( 0x0081C210, "MOVMD%02d.MIX" );
49+
SETSTRING( 0x008266A0, "MIXFILES\\MOVMD03.MIX" );
50+
SETSTRING( 0x008266B8, "MOVMD03.MIX" );
51+
SETSTRING( 0x008266C4, "MIXFILES\\MOVMD*.MIX" );
52+
SETSTRING( 0x008266D8, "MIXFILES\\MOVMD01.MIX" );
53+
SETSTRING( 0x008266F0, "MOVMD01.MIX" );
54+
SETSTRING( 0x00826748, "MOVMD*.MIX" );

0 commit comments

Comments
 (0)