PDA

View Full Version : Any interest in this?



IzNoGoD
26th March 2016, 16:43
Hey guys,

I managed to reduce the footprint of the cod2 server files to a whopping 325 meg, using some dirty, dirty libcod tricks.

Anyone interested in this?

IzNoGoD
26th March 2016, 16:46
Just to clarify: this modification works with sv_pure 1 as well, clients wont need to download anything

voron00
26th March 2016, 17:09
1043

10char

IzNoGoD
26th March 2016, 18:49
Firstly, add this to your libcod.cpp:



cHook *hook_fs_restart;

int fs_restart(int a1)
{
a1 = 1337;
*(int*)0x844020C = 1337;
hook_fs_restart->unhook();
int (*sig)(int a1);
*(int *)&sig = hook_fs_restart->from;
int ret = sig(a1);
hook_fs_restart->hook();
for(int* i = *(int**)0x849FD68; i != NULL; i = *(int**)i)
{
if(*(char**)(i+1))
{
if(!strncmp((char*)(*((int *)i + 1) + 512), "main", 4))
{
char* iwdname = (char*)(*((int *)i + 1) + 256);
int* checksum = (int*)(*((int *)i + 1) + 772);
int* checksump = (int*)(*((int *)i + 1) + 776);
if(!strncmp(iwdname, "iw_00", 5))
*checksum = 178615151;
else if(!strncmp(iwdname, "iw_03", 5))
*checksum = 1659111092;
else if(!strncmp(iwdname, "iw_04", 5))
*checksum = -1652414412;
else if(!strncmp(iwdname, "iw_05", 5))
*checksum = 1842349204;
else if(!strncmp(iwdname, "iw_06", 5))
*checksum = 1053665859;
else if(!strncmp(iwdname, "iw_07", 5))
*checksum = 1046874969;
else if(!strncmp(iwdname, "iw_08", 5))
*checksum = 1101180720;
else if(!strncmp(iwdname, "iw_09", 5))
*checksum = -621896007;
else if(!strncmp(iwdname, "iw_10", 5))
*checksum = 1334775335;
else if(!strncmp(iwdname, "iw_11", 5))
*checksum = -1980843666;
else if(!strncmp(iwdname, "iw_12", 5))
*checksum = -1333623355;
else if(!strncmp(iwdname, "iw_13", 5))
*checksum = 780394069;
else if(!strncmp(iwdname, "iw_14", 5))
*checksum = -1449716526;
else if(!strncmp(iwdname, "iw_15", 5))
*checksum = 181429573;
if(!strncmp(iwdname, "iw_00", 5))
*checksump = -611799356;
else if(!strncmp(iwdname, "iw_03", 5))
*checksump = -2036896789;
else if(!strncmp(iwdname, "iw_04", 5))
*checksump = -1238585410;
else if(!strncmp(iwdname, "iw_05", 5))
*checksump = 456204364;
else if(!strncmp(iwdname, "iw_06", 5))
*checksump = -1435860022;
else if(!strncmp(iwdname, "iw_07", 5))
*checksump = 508398181;
else if(!strncmp(iwdname, "iw_08", 5))
*checksump = -125161610;
else if(!strncmp(iwdname, "iw_09", 5))
*checksump = -1575356890;
else if(!strncmp(iwdname, "iw_10", 5))
*checksump = -1120125128;
else if(!strncmp(iwdname, "iw_11", 5))
*checksump = 1355810507;
else if(!strncmp(iwdname, "iw_12", 5))
*checksump = 1210336806;
else if(!strncmp(iwdname, "iw_13", 5))
*checksump = -1718123365;
else if(!strncmp(iwdname, "iw_14", 5))
*checksump = -2049617909;
else if(!strncmp(iwdname, "iw_15", 5))
*checksump = -914322415;
}
}
}
return ret;
}
And this on the proper spot:


hook_fs_restart = new cHook(0x80A337A, (int) fs_restart);
hook_fs_restart->hook();
Then, extract all your iwds (excluding the localized_english ones and iw_01 and iw_02, which contain sp maps only anyway). Extract them all to a different folder (extract iw_00 to a folder named iw_00 etc)
Then, run this python3 script from the root of that folder:


import os

startdir = os.getcwd()

for subdir in os.listdir(startdir):
iwddir = os.path.join(startdir, subdir)
for src_dir, dirs, files in os.walk(iwddir):
for file in files:
if(file.endswith(".iwi") or file.endswith(".mp3") or file.endswith(".wav") or file.endswith(".dds") or file.endswith(".d3dprt") or file.endswith(".hlsl") or file.endswith(".tga") or file.endswith(".jpg") or file.endswith(".rmb") or file.endswith(".roq") or file.endswith(".spd") or file.endswith(".tech") or file.endswith(".techset") or file.endswith(".tmp") or file.endswith(".tga0")):
os.remove(os.path.join(src_dir, file))
open(os.path.join(src_dir, file), 'a').close()


Then manually remove the sp maps from your folders (iw_00 and iw_03 contain some)

Then, run this .bat script from the root of your extraction folder:


for /D %%d in (*.*) do "C:\program files\7-zip\7z.exe" a -tzip "%%d.iwd" ".\%%d\*"

This should give you the iwds required. Then, extract all localized_english iwds into a single folder and delete everything except for the localizedstrings folder. Pack this folder into localized_english_iw99.iwd.

Now your iwds are ready.



Few things to note:
- To make sv_pure 1 work I had to un-randomize the checksumfeed. This means your server will be a little less secure against malicious players trying to join with modified iwd files (the 1337 is replacing the checksumfeed)
- iw_15 has a different checksum in patch 1.2. For patch 1.2 either backtrace what i did or just keep the file unmodified. Remove the iw_15 lines from the libcod.cpp as well for 1.2
- As most people will be running their servers without modified iwds, i strongly suggest to either not merge this into the libcod code, or to let it be controlled by some cvar.
- If you have any problem with this code, you should just run your cod server unmodified.

Ni3ls
26th March 2016, 19:39
What is the improvement compared to regular server? Speed, traffic?

IzNoGoD
26th March 2016, 20:18
Just hdd usage.

IzNoGoD
25th July 2016, 20:26
Follow-up on this: it caused some issues with custom maps, giving clients a iwd mismatch error. Might investigate some time in the future.