PDA

View Full Version : Patch switcher for cod2



IzNoGoD
7th February 2015, 13:17
Edit: This is outdated. Go to the next post.

Here's a python-based patch switcher for CoD2:


import socket
import StringIO
import csv
import os
import shutil
import _winreg as wreg
import sys
import subprocess
import Tkinter as tk

def switch_patch(version, frame):
source = "C:\\Program Files (x86)\\Activision\\Call of Duty 2 Patch switcher\\" + version + "\\"
dest = "C:\\Program Files (x86)\\Activision\\Call of Duty 2\\"
files = ["main\\iw_15.iwd", "CoD2MP_s.exe", "gfx_d3d_mp_x86_s.dll", "gfx_d3d_x86_s.dll"]
for file in files:
if os.path.exists(dest + file):
os.remove(dest + file)
if os.path.exists(source + file):
shutil.copyfile(source + file, dest + file)
if frame is not None:
frame.destroy()
return


version = '0.0'
if len(sys.argv) >= 2:
args = " ".join(sys.argv[2:])
if "+connect" in sys.argv[2:]:
index = sys.argv[2:].index("+connect")
info = sys.argv[2:][index + 1].split(":")
if len(info) >= 2:
ip = info[0]
port = int(info[1])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(2.0)
packet = "\xff\xff\xff\xffgetstatus"
try:
sock.sendto(packet, (ip, port))
response = sock.recvfrom(8196)[0]
f = StringIO.StringIO(response[4:])
reader = csv.reader(f, delimiter='\\')
for row in reader:
if 'shortversion' in row:
version = row[row.index('shortversion') + 1]
except:
pass

if version == "0.0":

root = tk.Tk()
args = ""
root.title("Patch Switcher")
versions = ["1.0", "1.2", "1.3"]
for v in versions:
tk.Button(root, text=v, width=25, height=3, command=lambda v=v:switch_patch(v, root)).pack()
root.mainloop()
else:
switch_patch(version, None)
key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\CoD2MP_s.exe")
try:
wreg.DeleteValue(key, 'Debugger')
except WindowsError:
pass
key.Close()

subprocess.call("C:\\Program Files (x86)\\Activision\\Call of Duty 2\\CoD2MP_s.exe " + args, cwd="C:\\Program Files (x86)\\Activision\\Call of Duty 2\\")

key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\CoD2MP_s.exe")
wreg.SetValueEx(key, 'Debugger', 0, wreg.REG_SZ, "\"C:\\Python27\\Pythonw.exe\" \"Versionswitcher.pyw\"")
key.Close()

Requirements:
Python 2.7 installed in C:/python27
CoD2 installed in C:/program files (x86)/activision/call of duty 2/
Cod2 patch switcher installed in C:/program files (x86)/activision/call of duty 2 patch switcher (www.iznogod.tweak.nl/cod2ps.rar )

How to install: Save the file as VersionSwitcher.pyw in C:/program files (x86)/activision/call of duty 2/ , then doubleclick the file once, it should set everything correctly.

From then on out it should hijack all calls to cod2mp_s.exe, get the +connect server version, switch patch and connect.
If no +connect is given, a UI will pop up asking for a version.

IzNoGoD
7th February 2015, 16:44
Ok, major update:



import socket
import io as StringIO
import csv
import os
import shutil
import winreg as wreg
import sys
import subprocess
import tkinter as tk
import urllib.request
import zipfile

ps_path = "_patchSwitcher"

def hook_cod2():
key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\CoD2MP_s.exe")
wreg.SetValueEx(key, 'Debugger', 0, wreg.REG_SZ, "\"pythonw.exe\" \"Versionswitcher.py\"")
key.Close()

def unhook_cod2():
key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\CoD2MP_s.exe")
try:
wreg.DeleteValue(key, 'Debugger')
except WindowsError:
pass
key.Close()

def install(frame):
if os.path.exists(ps_path):
shutil.rmtree(ps_path)
os.mkdir(ps_path)
urllib.request.urlretrieve("http://www.iznogod.tweak.nl/cod2ps.zip", os.path.join(ps_path, "cod2ps.zip"))
with zipfile.ZipFile(os.path.join(ps_path, 'cod2ps.zip'), 'r') as zf:
zf.extractall(ps_path)
os.remove(os.path.join(ps_path, "cod2ps.zip"))
hook_cod2()
frame.destroy()

def uninstall(frame):
if os.path.exists(ps_path):
shutil.rmtree(ps_path)
unhook_cod2()
frame.destroy()
sys.exit()

def switch_patch(version, frame):
source = os.path.join(ps_path, version)
files = [os.path.join("main", "iw_15.iwd"), "CoD2MP_s.exe", "gfx_d3d_mp_x86_s.dll", "gfx_d3d_x86_s.dll"]
for file in files:
if os.path.exists(file):
os.remove(file)
if os.path.exists(os.path.join(source, file)):
shutil.copyfile(os.path.join(source, file), file)
if frame is not None:
frame.destroy()
return


version = '0.0'
if len(sys.argv) >= 2:
args = " ".join(sys.argv[2:])
if "+connect" in sys.argv[2:]:
index = sys.argv[2:].index("+connect")
info = sys.argv[2:][index + 1].split(":")
if len(info) >= 2:
ip = info[0]
port = int(info[1])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(3.0)
try:
sock.sendto(b'\xff'b'\xff'b'\xff'b'\xff'b'getstatu s', (ip, port))
response = sock.recvfrom(8196)[0]
f = StringIO.StringIO(str(response[4:]))
reader = csv.reader(f, delimiter='\\')
for row in reader:
if 'shortversion' in row:
version = row[row.index("shortversion") + 2]
except:
pass
else:
#user is installing/uninstalling the utility
if os.path.exists(ps_path):
#uninstall and reinstall only
root = tk.Tk()
args = ""
root.title("Patch Switcher")
root.protocol('WM_DELETE_WINDOW', sys.exit)
tk.Button(root, text="Reinstall", width=25, height=3, command=lambda:install(root)).pack()
tk.Button(root, text="Uninstall", width=25, height=3, command=lambda:uninstall(root)).pack()
root.mainloop()
else:
#install only
root = tk.Tk()
args = ""
root.title("Patch Switcher")
root.protocol('WM_DELETE_WINDOW', sys.exit)
tk.Button(root, text="Install", width=25, height=3, command=lambda:install(root)).pack()
tk.Button(root, text="Uninstall", state='disabled', width=25, height=3).pack()
root.mainloop()
if version == "0.0":
root = tk.Tk()
args = ""
root.title("Patch Switcher")
root.protocol('WM_DELETE_WINDOW', sys.exit)
versions = ["1.0", "1.2", "1.3"]
for v in versions:
tk.Button(root, text=v, width=25, height=3, command=lambda v=v:switch_patch(v, root)).pack()
root.mainloop()
else:
switch_patch(version, None)

unhook_cod2()

subprocess.call("CoD2MP_s.exe " + args)

hook_cod2()


Minor update:

Save as VersionSwitcher.py in your cod2 root (next to cod2mp_s.exe)

Install python 3.x with option: Add to path in the installer

Double-click the VersionSwitcher.py file

Done.