├── DebugCompiler ├── version ├── xdrpc.dll ├── xdevkit.dll ├── hotload.dat.bak ├── packages.config ├── App.config └── Properties │ └── AssemblyInfo.cs ├── Default Menu.zip ├── T7CompilerLib ├── T7PCV2.db ├── packages.config ├── App.config ├── OpCodes │ ├── T7OP_Return.cs │ ├── T7Op_AbstractCall.cs │ ├── T7OP_Marker.cs │ ├── T7OP_GetHash.cs │ ├── T7OP_EvalFieldVariable.cs │ ├── T7OP_CallPtr.cs │ ├── T7OP_GetLocal.cs │ ├── T7OP_GetFuncPtr.cs │ ├── T7OP_GetLocalFunction.cs │ ├── T7OP_Call.cs │ ├── T7OP_GetString.cs │ ├── T7OP_LazyGetFunction.cs │ └── T7OP_Jump.cs ├── Properties │ └── AssemblyInfo.cs ├── ScriptComponents │ ├── T7ScriptSection.cs │ ├── T7NameSection.cs │ └── T7StringFixupsSection.cs └── Utility.cs ├── vscode-txgsc-1.0.8.vsix ├── T8CompilerLib ├── vm_codes.db2 ├── App.config ├── OpCodes │ ├── T89OP_Return.cs │ ├── T89OP_AbstractCall.cs │ ├── T89OP_Notification.cs │ ├── T89OP_GetHash.cs │ ├── T89OP_SetVariableFieldRef.cs │ ├── T89OP_CallPtr.cs │ ├── T89OP_GetGlobal.cs │ ├── T89OP_GetFuncPtr.cs │ ├── T89OP_EvalFieldVariable.cs │ ├── T89OP_GetString.cs │ ├── T89OP_GetLocal.cs │ ├── T89OP_SetLocal.cs │ ├── T89OP_SafeSetVFC.cs │ ├── T89OP_Call.cs │ ├── T89OP_Jump.cs │ └── T89OP_GetNumericValue.cs ├── Properties │ └── AssemblyInfo.cs ├── ScriptComponents │ ├── T89ScriptSection.cs │ ├── T89GlobalObjectsSection.cs │ └── T89IncludesSection.cs └── Utility.cs ├── TreyarchCompiler ├── Irony.dll ├── Enums │ ├── Masks.cs │ ├── Modes.cs │ ├── Games.cs │ └── Platforms.cs ├── Ionic.Zip.dll ├── Utilities │ ├── Keys.cs │ ├── FunctionDefinitions.cs │ ├── DecData.cs │ ├── Utilities.cs │ ├── WarningsData.cs │ ├── CompiledCode.cs │ └── Extensions.cs ├── Interface │ └── ICompiler.cs ├── FodyWeavers.xml ├── Properties │ ├── AssemblyInfo.cs │ └── Resources.Designer.cs ├── packages.config ├── Compiler.cs └── Games │ ├── BO3 │ └── BO3Syntax.cs │ ├── BO2 │ └── BO2Syntax.cs │ └── BLOPSCompiler.cs ├── Default Project ├── T7 │ ├── project.code-workspace │ ├── gsc.conf │ ├── scripts │ │ └── menu │ │ │ ├── main.gsc │ │ │ └── headers.gsc │ └── .vscode │ │ └── tasks.json └── T8 │ ├── project.code-workspace │ ├── gsc.conf │ ├── .vscode │ └── tasks.json │ └── scripts │ ├── headers.gsc │ └── main.gsc ├── t8cinternal ├── LazyLink.h ├── framework.h ├── dllmain.cpp ├── offsets.h ├── builtins.h ├── LazyLink.cpp ├── t8cinternal.filters ├── detours.h └── builtins.cpp ├── ExternalTestingUtility ├── App.config ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ └── Resources.Designer.cs ├── UI │ ├── Core │ │ ├── Interfaces │ │ │ ├── IResizableForm.cs │ │ │ └── IThemeableControl.cs │ │ └── Controls │ │ │ ├── CThemedTextbox.Designer.cs │ │ │ ├── CComboBox.cs │ │ │ ├── CErrorDialog.cs │ │ │ ├── CComboDialog.cs │ │ │ ├── CTitleBar.cs │ │ │ ├── CThemedTextbox.cs │ │ │ ├── CBorderedForm.Designer.cs │ │ │ └── CTitleBar.Designer.cs │ └── Application │ │ └── MainForm.cs └── app.manifest ├── External ├── Evasion │ └── EnvPatch.cs ├── packages.config ├── Features todo.txt ├── Quartz │ └── QAsm │ │ ├── Instructions │ │ └── QInstruction.cs │ │ ├── QCodeBlock.cs │ │ ├── QVariable.cs │ │ └── QObj.cs ├── PEStructures │ ├── PEImage.cs │ ├── PEDataDirectory.cs │ ├── PELoadConfigDirectory.cs │ ├── PETlsDirectory.cs │ ├── PERelocationDirectory.cs │ └── PEResourceDirectory.cs ├── Properties │ └── AssemblyInfo.cs ├── Reference │ └── x64hijackasm.txt ├── PointerExtensions.cs ├── ExThreads │ └── ThreadContextEx.cs └── PointerEx.cs ├── t7cinternal ├── Opcodes.h ├── framework.cpp ├── framework.h ├── offsets.h ├── t7cinternal.vcxproj.filters ├── Opcodes.cpp └── detours.h ├── README.md └── .gitattributes /DebugCompiler/version: -------------------------------------------------------------------------------- 1 | 3.1.7.4 -------------------------------------------------------------------------------- /Default Menu.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/Default Menu.zip -------------------------------------------------------------------------------- /DebugCompiler/xdrpc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/DebugCompiler/xdrpc.dll -------------------------------------------------------------------------------- /T7CompilerLib/T7PCV2.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/T7CompilerLib/T7PCV2.db -------------------------------------------------------------------------------- /vscode-txgsc-1.0.8.vsix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/vscode-txgsc-1.0.8.vsix -------------------------------------------------------------------------------- /DebugCompiler/xdevkit.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/DebugCompiler/xdevkit.dll -------------------------------------------------------------------------------- /T8CompilerLib/vm_codes.db2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/T8CompilerLib/vm_codes.db2 -------------------------------------------------------------------------------- /TreyarchCompiler/Irony.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/TreyarchCompiler/Irony.dll -------------------------------------------------------------------------------- /DebugCompiler/hotload.dat.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/DebugCompiler/hotload.dat.bak -------------------------------------------------------------------------------- /TreyarchCompiler/Enums/Masks.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Enums 2 | { 3 | public enum Masks 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /TreyarchCompiler/Ionic.Zip.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiversoftdev/t7-compiler/HEAD/TreyarchCompiler/Ionic.Zip.dll -------------------------------------------------------------------------------- /Default Project/T7/project.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": {} 8 | } -------------------------------------------------------------------------------- /Default Project/T8/project.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": {} 8 | } -------------------------------------------------------------------------------- /TreyarchCompiler/Enums/Modes.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Enums 2 | { 3 | public enum Modes 4 | { 5 | SP, 6 | MP, 7 | ZM 8 | } 9 | } -------------------------------------------------------------------------------- /TreyarchCompiler/Enums/Games.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Enums 2 | { 3 | public enum Games 4 | { 5 | T6, //BO2 6 | T7, //BO3 7 | T8 //BO4 8 | } 9 | } -------------------------------------------------------------------------------- /T7CompilerLib/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Default Project/T7/gsc.conf: -------------------------------------------------------------------------------- 1 | # Preprocessor conditions 2 | symbols=serious,zm 3 | 4 | # The game this project is for 5 | game=t7 6 | 7 | # The spot you want to inject to 8 | script=scripts/shared/duplicaterender_mgr.gsc -------------------------------------------------------------------------------- /T7CompilerLib/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /T8CompilerLib/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /TreyarchCompiler/Utilities/Keys.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Utilities 2 | { 3 | public class Keys 4 | { 5 | public string First { get; set; } 6 | public string Second { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /t8cinternal/LazyLink.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | 4 | class LazyLink 5 | { 6 | public: 7 | static void Init(); 8 | static void VM_OP_GetLazyFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 9 | }; -------------------------------------------------------------------------------- /ExternalTestingUtility/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /t8cinternal/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | // Windows Header Files 5 | #include 6 | #define EXPORT extern "C" __declspec(dllexport) -------------------------------------------------------------------------------- /TreyarchCompiler/Enums/Platforms.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Enums 2 | { 3 | public enum Platforms 4 | { 5 | Xbox, 6 | PS3, 7 | Steam, 8 | Tekno, //Removed for now 9 | PC, 10 | PS4, 11 | XB1 12 | } 13 | } -------------------------------------------------------------------------------- /TreyarchCompiler/Interface/ICompiler.cs: -------------------------------------------------------------------------------- 1 | using TreyarchCompiler.Utilities; 2 | 3 | namespace TreyarchCompiler.Interface 4 | { 5 | interface ICompiler 6 | { 7 | CompiledCode Compile(); 8 | 9 | CompiledCode Compile(string address); 10 | } 11 | } -------------------------------------------------------------------------------- /External/Evasion/EnvPatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace System.Evasion 8 | { 9 | public static class EnvPatch 10 | { 11 | // TODO 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ExternalTestingUtility/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TreyarchCompiler/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Default Project/T7/scripts/menu/main.gsc: -------------------------------------------------------------------------------- 1 | init() 2 | { 3 | } 4 | 5 | on_player_connect() 6 | { 7 | } 8 | 9 | on_player_spawned() 10 | { 11 | self endon("spawned_player"); 12 | 13 | while(true) 14 | { 15 | self enableInvulnerability(); 16 | self iPrintLnBold("Injected! Compiler by serious"); 17 | wait 1; 18 | } 19 | } -------------------------------------------------------------------------------- /t7cinternal/Opcodes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | 4 | class Opcodes 5 | { 6 | public: 7 | static void Init(); 8 | static void VM_OP_GetLazyFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 9 | static void VM_OP_GetLocalFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 10 | static void VM_OP_NOP(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 11 | }; -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Interfaces/IResizableForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | 8 | namespace Refract.UI.Core.Interfaces 9 | { 10 | internal interface IResizableForm 11 | { 12 | void WndProc_Implementation(ref Message m); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DebugCompiler/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /TreyarchCompiler/Utilities/FunctionDefinitions.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Utilities 2 | { 3 | public class FunctionDefinitions 4 | { 5 | public int start; 6 | public int size; 7 | public byte[] code; 8 | 9 | public FunctionDefinitions() 10 | { 11 | } 12 | 13 | public FunctionDefinitions(int start) 14 | { 15 | this.start = start; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_Return.cs: -------------------------------------------------------------------------------- 1 | namespace T89CompilerLib.OpCodes 2 | { 3 | public class T89OP_Return : T89OpCode 4 | { 5 | protected override ScriptOpCode Code 6 | { 7 | get 8 | { 9 | if (LastOpCode != null && ScriptOpMetadata.OpInfo[(int)LastOpCode.GetOpCode()].OperandType != ScriptOperandType.None) 10 | return ScriptOpCode.Return; 11 | return ScriptOpCode.End; 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_AbstractCall.cs: -------------------------------------------------------------------------------- 1 | using T89CompilerLib.ScriptComponents; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public class T89OP_AbstractCall : T89OpCode 6 | { 7 | private T89Import __import__; 8 | public T89Import Import 9 | { 10 | get => __import__; 11 | protected set 12 | { 13 | __import__?.References.Remove(this); 14 | __import__ = value; 15 | __import__?.References.Add(this); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Default Project/T8/gsc.conf: -------------------------------------------------------------------------------- 1 | # The game you want to inject to 2 | game=T8 3 | # Hook is the injection spot you want to hook 4 | # *IMPORTANT* This script will not be overwritten. The injector will simply hook this script to execute your script. 5 | # You can specify a file path (with or without .gsc), or a hash literal, ie: script_1baf22fcc0977005 (without .gsc!!!) 6 | # Recommended injection points: 7 | # MP: scripts\mp_common\bb.gsc 8 | # ZM: scripts\zm_common\load.gsc 9 | # Frontend: scripts\core_common\load_shared.gsc 10 | script=scripts\zm_common\load.gsc -------------------------------------------------------------------------------- /TreyarchCompiler/Utilities/DecData.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Utilities 2 | { 3 | public class DecData 4 | { 5 | private readonly string _declaration; 6 | private readonly string _call; 7 | 8 | public DecData(string declaration, string call) 9 | { 10 | _declaration = declaration; 11 | _call = call; 12 | } 13 | 14 | public string GetDeclaration() 15 | { 16 | return _declaration; 17 | } 18 | 19 | public string GetCall() 20 | { 21 | return _call; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Interfaces/IThemeableControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | 8 | namespace Refract.UI.Core.Interfaces 9 | { 10 | internal interface IThemeableControl 11 | { 12 | /// 13 | /// Get all controls to register with the theme manager, except the current control, which is always registered 14 | /// 15 | /// 16 | IEnumerable GetThemedControls(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > [!TIP] 2 | > If you are on MacOS and want to inject pre-compiled scripts to BO3, use Emma's [t7-osxternal](https://github.com/InvoxiPlayGames/t7-osxternal). 3 | 4 | # T7 & T8 GSC Compiler 5 | A compiler and injector for BO3/BO4 gsc\ 6 | Install via the installer https://github.com/shiversoftdev/t7-compiler/releases/tag/current \ 7 | Supports compilation from source and injection from compiled scripts\ 8 | 9 | # Credits 10 | Scobalula for his original decompiler\ 11 | SyGnUs for his CoD knowledge\ 12 | Original Black Ops 2 Compiler crew for their research\ 13 | Scrappy for livesplit builtin\ 14 | MFahim for assisting in identification of Nahimic OSD incompatibility. 15 | -------------------------------------------------------------------------------- /TreyarchCompiler/Utilities/Utilities.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Ionic.Zlib; 3 | 4 | namespace TreyarchCompiler.Utilities 5 | { 6 | internal class Utilities 7 | { 8 | protected static byte[] CompressBuffer(byte[] header) 9 | { 10 | using (var sm = new MemoryStream()) 11 | { 12 | using (var compressor = new ZlibStream(sm, CompressionMode.Compress, CompressionLevel.BestCompression)) 13 | { 14 | compressor.Write(header, 0, header.Length); 15 | compressor.Flush(); 16 | } 17 | return sm.ToArray(); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /External/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /t8cinternal/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "framework.h" 3 | #include "builtins.h" 4 | #include "detours.h" 5 | #include "LazyLink.h" 6 | 7 | BOOL APIENTRY DllMain( HMODULE hModule, 8 | DWORD ul_reason_for_call, 9 | LPVOID lpReserved 10 | ) 11 | { 12 | switch (ul_reason_for_call) 13 | { 14 | case DLL_PROCESS_ATTACH: 15 | // GSCBuiltins::Init(); 16 | // ScriptDetours::InstallHooks(); 17 | // LazyLink::Init(); 18 | break; 19 | case DLL_THREAD_ATTACH: 20 | case DLL_THREAD_DETACH: 21 | case DLL_PROCESS_DETACH: 22 | break; 23 | } 24 | return TRUE; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_Return.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public class T7OP_Return : T7OpCode 11 | { 12 | public T7OP_Return(EndianType endianess) : base(endianess) { } 13 | protected override ScriptOpCode Code 14 | { 15 | get 16 | { 17 | if (LastOpCode != null && ScriptOpMetadata.OpInfo[(int)LastOpCode.GetOpCode()].OperandType != ScriptOperandType.None) 18 | return ScriptOpCode.Return; 19 | return ScriptOpCode.End; 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Default Project/T7/scripts/menu/headers.gsc: -------------------------------------------------------------------------------- 1 | #include scripts\codescripts\struct; 2 | #include scripts\shared\callbacks_shared; 3 | #include scripts\shared\clientfield_shared; 4 | #include scripts\shared\math_shared; 5 | #include scripts\shared\system_shared; 6 | #include scripts\shared\util_shared; 7 | #include scripts\shared\hud_util_shared; 8 | #include scripts\shared\hud_message_shared; 9 | #include scripts\shared\hud_shared; 10 | #include scripts\shared\array_shared; 11 | 12 | #namespace serious; 13 | 14 | autoexec __init__sytem__() 15 | { 16 | system::register("serious", ::__init__, undefined, undefined); 17 | } 18 | 19 | __init__() 20 | { 21 | callback::on_start_gametype(::init); 22 | callback::on_connect(::on_player_connect); 23 | callback::on_spawned(::on_player_spawned); 24 | } -------------------------------------------------------------------------------- /External/Features todo.txt: -------------------------------------------------------------------------------- 1 | Freeze/Unfreeze memory value 2 | Suspend/Resume Process 3 | Inject DLL via: 4 | Managed dll inject 5 | SetWindowsHookEx 6 | Search memory via byte patterns 7 | Hijack processes for handles (rpc protocol) 8 | Internal.dll? 9 | proc.MapFunction 10 | self doppelgang 11 | https://github.com/aaaddress1/PR0CESS/tree/main/miniGhosting 12 | Event dispatcher system: 13 | - Emplace hooks such that an IPC event can fire and send info back to external 14 | Return address spoofing for x86 and x64 15 | 16 | Testing TODO: 17 | 18 | float/double RPC 19 | 20 | Bug Fixes TODO: 21 | 22 | Process wait monitor for a closed process does not correctly work. 23 | Still appears to be sporadic crashing sometimes in the process. I suspect todo with register values being corrupted. -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7Op_AbstractCall.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using T7CompilerLib.ScriptComponents; 8 | 9 | namespace T7CompilerLib.OpCodes 10 | { 11 | public class T7OP_AbstractCall : T7OpCode 12 | { 13 | private T7Import __import__; 14 | 15 | public T7OP_AbstractCall(EndianType endianess) : base(endianess) { } 16 | 17 | protected T7Import Import 18 | { 19 | get => __import__; 20 | set 21 | { 22 | __import__?.References.Remove(this); 23 | __import__ = value; 24 | __import__?.References.Add(this); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TreyarchCompiler/Utilities/WarningsData.cs: -------------------------------------------------------------------------------- 1 | namespace TreyarchCompiler.Utilities 2 | { 3 | public class WarningsData 4 | { 5 | public readonly string Declaration; 6 | public readonly string Warning; 7 | public int Refs; 8 | 9 | public WarningsData(string declaration, string warning) 10 | { 11 | Declaration = declaration; 12 | Warning = warning; 13 | Refs = 1; 14 | } 15 | 16 | public string GetDeclaration() 17 | { 18 | return Declaration; 19 | } 20 | 21 | public string GetWarning() 22 | { 23 | return Warning; 24 | } 25 | 26 | public int GetRef() 27 | { 28 | return Refs; 29 | } 30 | 31 | public void OneUpRefs() 32 | { 33 | Refs++; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Default Project/T7/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "inject", 8 | "type": "shell", 9 | "command": "C:\\t7Compiler\\DebugCompiler.exe", 10 | "args": [ 11 | "--build" 12 | ], 13 | "group": { 14 | "kind": "test", 15 | "isDefault": true 16 | }, 17 | "presentation": { 18 | "reveal": "always", 19 | "panel": "dedicated", 20 | "echo": false, 21 | "clear": true, 22 | "focus": true, 23 | }, 24 | "options": { 25 | "cwd": "${workspaceRoot}" 26 | } 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /Default Project/T8/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "inject", 8 | "type": "shell", 9 | "command": "C:\\t7compiler\\debugcompiler.exe", 10 | "args": [ 11 | "--build" 12 | ], 13 | "group": { 14 | "kind": "test", 15 | "isDefault": true 16 | }, 17 | "presentation": { 18 | "reveal": "always", 19 | "panel": "dedicated", 20 | "echo": false, 21 | "clear": true, 22 | "focus": true, 23 | }, 24 | "options": { 25 | "cwd": "${workspaceRoot}" 26 | } 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /Default Project/T8/scripts/headers.gsc: -------------------------------------------------------------------------------- 1 | #include scripts\core_common\struct; 2 | #include scripts\core_common\callbacks_shared; 3 | #include scripts\core_common\clientfield_shared; 4 | #include scripts\core_common\math_shared; 5 | #include scripts\core_common\system_shared; 6 | #include scripts\core_common\util_shared; 7 | #include scripts\core_common\hud_util_shared; 8 | #include scripts\core_common\hud_message_shared; 9 | #include scripts\core_common\hud_shared; 10 | #include scripts\core_common\array_shared; 11 | #include scripts\core_common\flag_shared; 12 | 13 | #namespace clientids_shared; 14 | 15 | //required 16 | autoexec __init__sytem__() 17 | { 18 | system::register("clientids_shared", &__init__, undefined, undefined); 19 | } 20 | 21 | //required 22 | __init__() 23 | { 24 | callback::on_start_gametype(&init); 25 | callback::on_connect(&onPlayerConnect); 26 | callback::on_spawned(&onPlayerSpawned); 27 | } -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_Notification.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_Notification : T89OpCode 6 | { 7 | private byte NumParams; 8 | public T89OP_Notification(ScriptOpCode Op, byte numParams) 9 | { 10 | Code = Op; 11 | NumParams = numParams; 12 | } 13 | 14 | protected override byte[] Serialize(ushort EmissionValue) 15 | { 16 | byte[] data = new byte[GetSize()]; 17 | base.Serialize(EmissionValue).CopyTo(data, 0); 18 | data[T89OP_SIZE] = NumParams; 19 | return data; 20 | } 21 | 22 | public override uint GetCommitDataAddress() 23 | { 24 | return CommitAddress + T89OP_SIZE; 25 | } 26 | 27 | public override uint GetSize() 28 | { 29 | return T89OP_SIZE + 1 + 1; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_Marker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public sealed class T7OP_Marker : T7OpCode 11 | { 12 | public string Identifier { get; private set; } 13 | public T7OP_Marker(string identifier, EndianType endianess) : base(ScriptOpCode.Nop, endianess) 14 | { 15 | Identifier = identifier; 16 | } 17 | 18 | protected override byte[] Serialize(ushort EmissionValue) 19 | { 20 | byte[] data = new byte[GetSize()]; 21 | return data; 22 | } 23 | 24 | public override uint GetCommitDataAddress() 25 | { 26 | return CommitAddress; 27 | } 28 | 29 | public override uint GetSize() 30 | { 31 | return 0; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_GetHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_GetHash : T89OpCode 6 | { 7 | ulong Hash; 8 | public T89OP_GetHash(ulong hash) : base(ScriptOpCode.GetHash) 9 | { 10 | Hash = hash; 11 | } 12 | 13 | protected override byte[] Serialize(ushort EmissionValue) 14 | { 15 | byte[] data = new byte[GetSize()]; 16 | 17 | base.Serialize(EmissionValue).CopyTo(data, 0); 18 | 19 | BitConverter.GetBytes(Hash).CopyTo(data, GetCommitDataAddress() - CommitAddress); 20 | 21 | return data; 22 | } 23 | 24 | public override uint GetCommitDataAddress() 25 | { 26 | return (CommitAddress + T89OP_SIZE).AlignValue(sizeof(ulong)); 27 | } 28 | 29 | public override uint GetSize() 30 | { 31 | return 8 + GetCommitDataAddress() - CommitAddress; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /External/Quartz/QAsm/Instructions/QInstruction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace System.Quartz.QAsm.Instructions 8 | { 9 | // root class for quartz meta instructions 10 | public abstract class QInstruction 11 | { 12 | // Doubly linked list internally to use some traversal information when emitting bytecode 13 | public QInstruction Next { get; private set; } 14 | public QInstruction Previous { get; private set; } 15 | 16 | // Allows us to get information about our context scope 17 | public QCodeBlock ParentBlock { get; set; } 18 | 19 | public void Link(QInstruction next) 20 | { 21 | if(Next != null) 22 | { 23 | throw new InvalidOperationException("Tried to link an instruction which already has been linked"); 24 | } 25 | Next = next; 26 | next.Previous = this; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_SetVariableFieldRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_SetVariableFieldRef : T89OpCode 6 | { 7 | private uint VariableHash; 8 | public T89OP_SetVariableFieldRef(uint variable_hash) 9 | { 10 | Code = ScriptOpCode.SetVariableFieldRef; 11 | VariableHash = variable_hash; 12 | } 13 | 14 | protected override byte[] Serialize(ushort EmissionValue) 15 | { 16 | byte[] data = new byte[GetSize()]; 17 | base.Serialize(EmissionValue).CopyTo(data, 0); 18 | BitConverter.GetBytes(VariableHash).CopyTo(data, GetCommitDataAddress() - CommitAddress); 19 | return data; 20 | } 21 | 22 | public override uint GetCommitDataAddress() 23 | { 24 | return (CommitAddress + T89OP_SIZE).AlignValue(0x4); 25 | } 26 | 27 | public override uint GetSize() 28 | { 29 | return 4 + GetCommitDataAddress() - CommitAddress; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_GetHash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public sealed class T7OP_GetHash : T7OpCode 11 | { 12 | uint Hash; 13 | public T7OP_GetHash(uint hash, EndianType endianess) : base(ScriptOpCode.GetHash, endianess) 14 | { 15 | Hash = hash; 16 | } 17 | 18 | protected override byte[] Serialize(ushort EmissionValue) 19 | { 20 | byte[] data = new byte[GetSize()]; 21 | 22 | base.Serialize(EmissionValue).CopyTo(data, 0); 23 | 24 | Hash.GetBytes(Endianess).CopyTo(data, GetCommitDataAddress() - CommitAddress); 25 | 26 | return data; 27 | } 28 | 29 | public override uint GetCommitDataAddress() 30 | { 31 | return (CommitAddress + T7OP_SIZE).AlignValue(0x4); 32 | } 33 | 34 | public override uint GetSize() 35 | { 36 | return 4 + GetCommitDataAddress() - CommitAddress; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TreyarchCompiler/Utilities/CompiledCode.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TreyarchCompiler.Utilities 4 | { 5 | public class CompiledCode 6 | { 7 | public string Error; 8 | public List Warning; 9 | public byte[] CompiledScript; 10 | public byte[] StubScriptData; 11 | public Dictionary WriteData; 12 | public Dictionary MaskData; 13 | public byte[] OpcodeMap; 14 | public byte[] Dll; 15 | public bool RequiresGSI; 16 | public Dictionary HashMap; 17 | public List OpcodeEmissions; 18 | public string StubbedScript; 19 | 20 | internal CompiledCode() 21 | { 22 | Error = string.Empty; 23 | Warning = new List(); 24 | CompiledScript = new byte[0]; 25 | WriteData = new Dictionary(); 26 | Dll = new byte[0]; 27 | HashMap = new Dictionary(); 28 | OpcodeEmissions = new List(); 29 | StubbedScript = null; 30 | StubScriptData = null; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /ExternalTestingUtility/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace t7c_installer.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /t8cinternal/offsets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | 4 | // dont mess with these because when I add new games, these macros will change 5 | 6 | #define OFFSET(x) ((INT64)GetModuleHandle(NULL) + (INT64)x) 7 | 8 | #define OFF_IsProfileBuild OFFSET(0x49611A0) 9 | #define OFF_ScrVm_GetInt OFFSET(0x2773B50) 10 | #define OFF_ScrVm_GetString OFFSET(0x2774840) 11 | #define OFF_ScrVm_GetNumParam OFFSET(0x2774440) 12 | #define OFF_ScrVm_AddInt OFFSET(0x276EB80) 13 | #define OFF_ScrVm_AddBool OFFSET(0x276E760) 14 | #define OFF_ScrVm_AddUndefined OFFSET(0x4072AE0) 15 | #define OFF_ScrVm_Opcodes OFFSET(0x4EED340) 16 | #define OFF_Scr_GetFunction OFFSET(0x33AF840) 17 | #define OFF_Scr_GetMethod OFFSET(0x33AFC20) 18 | #define OFF_CScr_GetFunction OFFSET(0x1F13140) 19 | #define OFF_CScr_GetMethod OFFSET(0x1F13650) 20 | #define OFF_DB_FindXAssetHeader OFFSET(0x2EB75B0) 21 | #define OFF_xAssetScriptParseTree OFFSET(0x912BBB0) 22 | #define XASSETTYPE_SCRIPTPARSETREE 0x30 23 | #define OFF_gObjFileInfo OFFSET(0x82efcd0) 24 | #define OFF_gObjFileInfoCount OFFSET(0x82f76b0) 25 | #define OFF_s_runningUILevel OFFSET(0x0000000008B50819) 26 | #define OFF_Scr_GscObjLink OFFSET(0x2748E70) 27 | #define OFF_MemTreeBuffers OFFSET(0x7DAFC20) -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CThemedTextbox.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace SMC.UI.Core.Controls 3 | { 4 | partial class CThemedTextbox 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Component Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | components = new System.ComponentModel.Container(); 33 | } 34 | 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_CallPtr.cs: -------------------------------------------------------------------------------- 1 | namespace T89CompilerLib.OpCodes 2 | { 3 | public sealed class T89OP_CallPtr : T89OpCode 4 | { 5 | private byte NumParams; 6 | public T89OP_CallPtr(uint context, byte numparams) 7 | { 8 | NumParams = numparams; 9 | 10 | if(context.HasContext(ScriptContext.HasCaller)) 11 | { 12 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptMethodThreadCallPointer : ScriptOpCode.ScriptMethodCallPointer; 13 | } 14 | else 15 | { 16 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptThreadCallPointer : ScriptOpCode.ScriptFunctionCallPointer; 17 | } 18 | } 19 | 20 | protected override byte[] Serialize(ushort EmissionValue) 21 | { 22 | byte[] data = new byte[GetSize()]; 23 | 24 | base.Serialize(EmissionValue).CopyTo(data, 0); 25 | 26 | data[2] = NumParams; 27 | 28 | return data; 29 | } 30 | 31 | public override uint GetCommitDataAddress() 32 | { 33 | return CommitAddress + T89OP_SIZE; 34 | } 35 | 36 | public override uint GetSize() 37 | { 38 | return T89OP_SIZE + 1 + 1; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_GetGlobal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using T89CompilerLib.ScriptComponents; 3 | 4 | namespace T89CompilerLib.OpCodes 5 | { 6 | public sealed class T89OP_GetGlobal : T89OpCode 7 | { 8 | private T89GlobalRef _global; 9 | private T89GlobalRef Global 10 | { 11 | get 12 | { 13 | return _global; 14 | } 15 | set 16 | { 17 | _global?.References.Remove(this); 18 | _global = value; 19 | _global?.References.Add(this); 20 | } 21 | } 22 | public T89OP_GetGlobal(T89GlobalRef global, bool isRef) 23 | { 24 | Code = isRef ? ScriptOpCode.GetGlobalObjectRef : ScriptOpCode.GetGlobalObject; 25 | Global = global; 26 | } 27 | 28 | protected override byte[] Serialize(ushort EmissionValue) 29 | { 30 | byte[] data = new byte[GetSize()]; 31 | base.Serialize(EmissionValue).CopyTo(data, 0); 32 | return data; 33 | } 34 | 35 | public override uint GetCommitDataAddress() 36 | { 37 | return CommitAddress + T89OP_SIZE; 38 | } 39 | 40 | public override uint GetSize() 41 | { 42 | return T89OP_SIZE + 1 + 1; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DebugCompiler/App.config: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_GetFuncPtr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using T89CompilerLib.ScriptComponents; 3 | 4 | namespace T89CompilerLib.OpCodes 5 | { 6 | public sealed class T89OP_GetFuncPtr : T89OP_AbstractCall 7 | { 8 | internal T89OP_GetFuncPtr(T89Import import, ScriptOpCode code) 9 | { 10 | Code = code; 11 | Import = import; 12 | } 13 | 14 | protected override byte[] Serialize(ushort EmissionValue) 15 | { 16 | byte[] data = new byte[GetSize()]; 17 | 18 | base.Serialize(EmissionValue).CopyTo(data, 0); 19 | 20 | uint WriteAddress = (GetCommitDataAddress()).AlignValue(0x8) - CommitAddress; 21 | 22 | BitConverter.GetBytes(Import.Function).CopyTo(data, WriteAddress); 23 | //BitConverter.GetBytes(Import.Namespace).CopyTo(data, WriteAddress + 4); 24 | 25 | return data; 26 | } 27 | 28 | public override uint GetCommitDataAddress() 29 | { 30 | return CommitAddress + T89OP_SIZE; 31 | } 32 | 33 | //OP_CODE 0x2 34 | //NUMPARAMS 0x1 35 | //padding 0x1 36 | //QWORD ALIGN 37 | //Function 38 | //0 (x4) 39 | public override uint GetSize() 40 | { 41 | return (GetCommitDataAddress()).AlignValue(0x8) + 4 + 4 - CommitAddress; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_EvalFieldVariable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public sealed class T7OP_EvalFieldVariable : T7OpCode 11 | { 12 | private uint VariableHash; 13 | public T7OP_EvalFieldVariable(uint variable_hash, uint context, EndianType endianess) : base(endianess) 14 | { 15 | if ((context & (uint)ScriptContext.IsRef) > 0) 16 | Code = ScriptOpCode.EvalFieldVariableRef; 17 | else 18 | Code = ScriptOpCode.EvalFieldVariable; 19 | 20 | VariableHash = variable_hash; 21 | } 22 | 23 | protected override byte[] Serialize(ushort EmissionValue) 24 | { 25 | byte[] data = new byte[GetSize()]; 26 | 27 | base.Serialize(EmissionValue).CopyTo(data, 0); 28 | 29 | VariableHash.GetBytes(Endianess).CopyTo(data, GetCommitDataAddress() - CommitAddress); 30 | 31 | return data; 32 | } 33 | 34 | public override uint GetCommitDataAddress() 35 | { 36 | return (CommitAddress + T7OP_SIZE).AlignValue(0x4); 37 | } 38 | 39 | public override uint GetSize() 40 | { 41 | return 4 + GetCommitDataAddress() - CommitAddress; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /External/PEStructures/PEImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Immutable; 4 | using System.Linq; 5 | using System.Reflection.PortableExecutable; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace System.PEStructures 10 | { 11 | public class PEImage 12 | { 13 | public PEReader Reader { get; } 14 | public PEHeaders Headers => Reader?.PEHeaders; 15 | public PEExportDirectory Exports { get; } 16 | public PEImportDirectory Imports { get; } 17 | public PELoadConfigDirectory LoadConfigDirectory { get; } 18 | public PERelocationDirectory Relocations { get; } 19 | public PEResourceDirectory Resources { get; } 20 | public PETlsDirectory TLSDirectory { get; } 21 | public PEImage(Memory imageData) 22 | { 23 | Reader = new PEReader(imageData.ToArray().ToImmutableArray()); 24 | if (Headers?.PEHeader is null) throw new BadImageFormatException("The provided file was not a valid PE"); 25 | Exports = new PEExportDirectory(Headers, imageData); 26 | Imports = new PEImportDirectory(Headers, imageData); 27 | LoadConfigDirectory = new PELoadConfigDirectory(Headers, imageData); 28 | Relocations = new PERelocationDirectory(Headers, imageData); 29 | Resources = new PEResourceDirectory(Headers, imageData); 30 | TLSDirectory = new PETlsDirectory(Headers, imageData); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /T8CompilerLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("T89CompilerLib")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("T89CompilerLib")] 12 | [assembly: AssemblyCopyright("Copyright © 2020")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("7527fb74-e8ac-43f1-9e48-e9d4d2b5d5b3")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /TreyarchCompiler/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("InfinityCompiler")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("InfinityCompiler")] 12 | [assembly: AssemblyCopyright("Copyright © 2017")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("e66208e7-27e8-4829-9211-bda6182902ca")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_EvalFieldVariable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_EvalFieldVariable : T89OpCode 6 | { 7 | public uint VariableHash { get; private set; } 8 | public T89OP_EvalFieldVariable(uint variable_hash, uint context) 9 | { 10 | if ((context & (uint)ScriptContext.IsRef) > 0) 11 | Code = ScriptOpCode.EvalFieldVariableRef; 12 | else 13 | Code = ScriptOpCode.CastAndEvalFieldVariable; 14 | 15 | VariableHash = variable_hash; 16 | } 17 | 18 | public void AdjustContext(bool isRef) 19 | { 20 | if(isRef) 21 | Code = ScriptOpCode.EvalFieldVariableRef; 22 | else 23 | Code = ScriptOpCode.EvalFieldVariable; 24 | } 25 | 26 | protected override byte[] Serialize(ushort EmissionValue) 27 | { 28 | byte[] data = new byte[GetSize()]; 29 | 30 | base.Serialize(EmissionValue).CopyTo(data, 0); 31 | 32 | BitConverter.GetBytes(VariableHash).CopyTo(data, GetCommitDataAddress() - CommitAddress); 33 | 34 | return data; 35 | } 36 | 37 | public override uint GetCommitDataAddress() 38 | { 39 | return (CommitAddress + T89OP_SIZE).AlignValue(0x4); 40 | } 41 | 42 | public override uint GetSize() 43 | { 44 | return 4 + GetCommitDataAddress() - CommitAddress; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /External/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("External")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("External")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("810bdf68-87bb-45a2-ac4f-87643045bf4c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_GetString.cs: -------------------------------------------------------------------------------- 1 | using T89CompilerLib.ScriptComponents; 2 | 3 | //Class should be finished. 4 | namespace T89CompilerLib.OpCodes 5 | { 6 | public sealed class T89OP_GetString : T89OpCode 7 | { 8 | private T89StringTableEntry __ref__; 9 | public T89StringTableEntry ReferencedString 10 | { 11 | get => __ref__; 12 | private set 13 | { 14 | __ref__?.References.Remove(this); 15 | __ref__ = value; 16 | __ref__?.References.Add(this); 17 | } 18 | } 19 | 20 | public T89OP_GetString(ScriptOpCode op_info, T89StringTableEntry refstring) : base(op_info) 21 | { 22 | ReferencedString = refstring; 23 | } 24 | 25 | protected override byte[] Serialize(ushort EmissionValue) 26 | { 27 | byte[] data = new byte[GetSize()]; 28 | 29 | base.Serialize(EmissionValue).CopyTo(data, 0); 30 | 31 | //We dont need to pass a real pointer here. Game overwrites it on load anyways 32 | new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }.CopyTo(data, GetCommitDataAddress() - CommitAddress); 33 | 34 | return data; 35 | } 36 | 37 | public override uint GetCommitDataAddress() 38 | { 39 | return (CommitAddress + T89OP_SIZE).AlignValue(0x4); 40 | } 41 | 42 | public override uint GetSize() 43 | { 44 | return 4 + GetCommitDataAddress() - CommitAddress; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /DebugCompiler/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DebugCompiler")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DebugCompiler")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a45bc8f5-cb13-4006-9eae-a07ca7cc091c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /T7CompilerLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("T7CompilerLib")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("T7CompilerLib")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7527fb74-e8ac-43f1-9e48-e9d4d2b5d5b3")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ExternalTestingUtility/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("t7c_installer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("t7c_installer")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1dc7ce8b-f111-4e49-b915-b88e7d64358b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CComboBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | 10 | namespace SMC.UI.Core.Controls 11 | { 12 | public class CComboBox : ComboBox 13 | { 14 | private const int WM_PAINT = 0xF; 15 | private int buttonWidth = SystemInformation.HorizontalScrollBarArrowWidth; 16 | protected override void WndProc(ref Message m) 17 | { 18 | base.WndProc(ref m); 19 | if (m.Msg == WM_PAINT) 20 | { 21 | using (var g = Graphics.FromHwnd(Handle)) 22 | { 23 | // Uncomment this if you don't want the "highlight border". 24 | 25 | using (var p = new Pen(this.BorderColor, 1)) 26 | { 27 | g.DrawRectangle(p, 0, 0, Width - 1, Height - 1); 28 | } 29 | using (var p = new Pen(this.BorderColor, 1)) 30 | { 31 | g.DrawRectangle(p, 0, 0, Width - buttonWidth - 1, Height - 1); 32 | } 33 | } 34 | } 35 | } 36 | 37 | public CComboBox() 38 | { 39 | BorderColor = Color.DimGray; 40 | } 41 | 42 | [Browsable(true)] 43 | [Category("Appearance")] 44 | [DefaultValue(typeof(Color), "DimGray")] 45 | public Color BorderColor { get; set; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_GetLocal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_GetLocal : T89OpCode 6 | { 7 | 8 | private T89OP_SafeCreateLocalVariables LocalVariables; 9 | private uint Hash; 10 | 11 | public T89OP_GetLocal(T89OP_SafeCreateLocalVariables cache, uint hash, ScriptOpCode Op) 12 | { 13 | if (!cache.TryGetLocal(hash, out byte index)) 14 | throw new ArgumentException("Tried to access an undefined variable."); 15 | 16 | LocalVariables = cache; 17 | Hash = hash; 18 | Code = Op; 19 | } 20 | 21 | protected override byte[] Serialize(ushort EmissionValue) 22 | { 23 | byte[] data = new byte[GetSize()]; 24 | 25 | base.Serialize(EmissionValue).CopyTo(data, 0); 26 | 27 | if (!LocalVariables.TryGetLocal(Hash, out byte Index)) 28 | throw new ArgumentException("A local variable that was referenced inside the export was removed from the variables cache without purging references to it"); 29 | 30 | data[GetCommitDataAddress() - CommitAddress] = Index; 31 | 32 | return data; 33 | } 34 | 35 | public override uint GetCommitDataAddress() 36 | { 37 | return CommitAddress + T89OP_SIZE; 38 | } 39 | 40 | public override uint GetSize() 41 | { 42 | return T89OP_SIZE + 1 + 1; 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return "var_" + Hash.ToString("X"); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_SetLocal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_SetLocal : T89OpCode 6 | { 7 | 8 | private T89OP_SafeCreateLocalVariables LocalVariables; 9 | private uint Hash; 10 | 11 | public T89OP_SetLocal(T89OP_SafeCreateLocalVariables cache, uint hash) 12 | { 13 | if (!cache.TryGetLocal(hash, out byte index)) 14 | throw new ArgumentException("Tried to access an undefined variable."); 15 | 16 | LocalVariables = cache; 17 | Hash = hash; 18 | Code = ScriptOpCode.SetLocalVariableCached; 19 | } 20 | 21 | protected override byte[] Serialize(ushort EmissionValue) 22 | { 23 | byte[] data = new byte[GetSize()]; 24 | 25 | base.Serialize(EmissionValue).CopyTo(data, 0); 26 | 27 | if (!LocalVariables.TryGetLocal(Hash, out byte Index)) 28 | throw new ArgumentException("A local variable that was referenced inside the export was removed from the variables cache without purging references to it"); 29 | 30 | data[T89OP_SIZE] = Index; 31 | 32 | return data; 33 | } 34 | 35 | public override uint GetCommitDataAddress() 36 | { 37 | return CommitAddress + T89OP_SIZE; 38 | } 39 | 40 | public override uint GetSize() 41 | { 42 | return T89OP_SIZE + 1 + 1; 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return "var_" + Hash.ToString("X"); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_CallPtr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace T7CompilerLib.OpCodes 10 | { 11 | public sealed class T7OP_CallPtr : T7OpCode 12 | { 13 | private byte NumParams; 14 | public T7OP_CallPtr(uint context, byte numparams, EndianType endianess) : base (endianess) 15 | { 16 | NumParams = numparams; 17 | 18 | if(context.HasContext(ScriptContext.HasCaller)) 19 | { 20 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptMethodThreadCallPointer : ScriptOpCode.ScriptMethodCallPointer; 21 | } 22 | else 23 | { 24 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptThreadCallPointer : ScriptOpCode.ScriptFunctionCallPointer; 25 | } 26 | } 27 | 28 | protected override byte[] Serialize(ushort EmissionValue) 29 | { 30 | byte[] data = new byte[GetSize()]; 31 | 32 | base.Serialize(EmissionValue).CopyTo(data, 0); 33 | 34 | data[T7OP_SIZE] = NumParams; 35 | 36 | return data; 37 | } 38 | 39 | public override uint GetCommitDataAddress() 40 | { 41 | return CommitAddress + T7OP_SIZE; 42 | } 43 | 44 | public override uint GetSize() 45 | { 46 | if(Endianess == EndianType.LittleEndian) 47 | return T7OP_SIZE + 1 + 1; 48 | return T7OP_SIZE + 1; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_GetLocal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public sealed class T7OP_GetLocal : T7OpCode 11 | { 12 | 13 | private T7OP_SafeCreateLocalVariables LocalVariables; 14 | private uint Hash; 15 | 16 | public T7OP_GetLocal(T7OP_SafeCreateLocalVariables cache, uint hash, ScriptOpCode Op, EndianType endianess) : base(endianess) 17 | { 18 | if (!cache.TryGetLocal(hash, out byte index)) 19 | throw new ArgumentException("Tried to access an undefined variable."); 20 | 21 | LocalVariables = cache; 22 | Hash = hash; 23 | Code = Op; 24 | } 25 | 26 | protected override byte[] Serialize(ushort EmissionValue) 27 | { 28 | byte[] data = new byte[GetSize()]; 29 | 30 | base.Serialize(EmissionValue).CopyTo(data, 0); 31 | 32 | if (!LocalVariables.TryGetLocal(Hash, out byte Index)) 33 | throw new ArgumentException("A local variable that was referenced inside the export was removed from the variables cache without purging references to it"); 34 | 35 | data[GetCommitDataAddress() - CommitAddress] = Index; 36 | 37 | return data; 38 | } 39 | 40 | public override uint GetCommitDataAddress() 41 | { 42 | return CommitAddress + T7OP_SIZE; 43 | } 44 | 45 | public override uint GetSize() 46 | { 47 | return T7OP_SIZE * 2; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_SafeSetVFC.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_SafeSetVFC : T89OpCode 6 | { 7 | 8 | private T89OP_SafeCreateLocalVariables LocalVariables; 9 | private uint Hash; 10 | 11 | public T89OP_SafeSetVFC(T89OP_SafeCreateLocalVariables cache, uint hash) 12 | { 13 | if (!cache.TryGetLocal(hash, out byte index)) 14 | throw new ArgumentException("Tried to access an undefined variable."); 15 | 16 | LocalVariables = cache; 17 | Hash = hash; 18 | Code = ScriptOpCode.SafeSetVariableFieldCached; 19 | } 20 | 21 | protected override byte[] Serialize(ushort EmissionValue) 22 | { 23 | byte[] data = new byte[GetSize()]; 24 | 25 | base.Serialize(EmissionValue).CopyTo(data, 0); 26 | 27 | if (!LocalVariables.TryGetLocal(Hash, out byte Index)) 28 | throw new ArgumentException("A local variable that was referenced inside the export was removed from the variables cache without purging references to it"); 29 | 30 | data[GetCommitDataAddress() - CommitAddress] = Index; 31 | 32 | return data; 33 | } 34 | 35 | public override uint GetCommitDataAddress() 36 | { 37 | return CommitAddress + T89OP_SIZE; 38 | } 39 | 40 | public override uint GetSize() 41 | { 42 | return T89OP_SIZE + 1 + 1; 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return "var_" + Hash.ToString("X") + " = "; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /t7cinternal/framework.cpp: -------------------------------------------------------------------------------- 1 | #include "framework.h" 2 | 3 | #pragma section(".offsets",read,write) 4 | // this is the result of severe brain damage 5 | // this is a function used as MSELECT(steam_offset, msstore_offset) 6 | // mov rax, 0x1122334455667788 (replaced with game base address) 7 | // add rax, rcx (rcx replaced with rdx if its msstore) 8 | // ret 9 | __declspec(allocate(".offsets")) const char MSELECT[] = 10 | { 11 | 0x48, 0xB8, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 12 | 0x48, 0x01, 0xC8, // c8 -> d0 for rcx -> rdx 13 | 0xC3 14 | }; 15 | 16 | #pragma optimize("",off) 17 | bool is_tls_initialized = false; 18 | void NTAPI tls_callback(PVOID DllHandle, DWORD dwReason, PVOID) 19 | { 20 | if (is_tls_initialized) 21 | { 22 | return; 23 | } 24 | is_tls_initialized = true; 25 | 26 | VirtualProtect((LPVOID)MSELECT, sizeof(MSELECT), PAGE_EXECUTE_READWRITE, &dwReason); 27 | auto base_address_game = *(uint64_t*)((uint64_t)(NtCurrentTeb()->ProcessEnvironmentBlock) + 0x10); 28 | *(uint64_t*)(MSELECT + 2) = base_address_game; 29 | 30 | if (*(uint32_t*)(base_address_game + 0x3C) == 0x1A0) // if we are windows store exe 31 | { 32 | *(uint8_t*)(MSELECT + 0xC) = 0xd0; // use rdx 33 | } 34 | } 35 | #pragma optimize("",on) 36 | 37 | #pragma comment (linker, "/INCLUDE:_tls_used") 38 | #pragma comment (linker, "/INCLUDE:tls_callback_func") 39 | #pragma const_seg(".CRT$XLF") 40 | EXTERN_C const 41 | PIMAGE_TLS_CALLBACK tls_callback_func = tls_callback; 42 | #pragma const_seg() 43 | 44 | void chgmem(__int64 addy, __int32 size, void* copy) 45 | { 46 | DWORD oldprotect; 47 | VirtualProtect((void*)addy, size, PAGE_EXECUTE_READWRITE, &oldprotect); 48 | memcpy((void*)addy, copy, size); 49 | VirtualProtect((void*)addy, size, oldprotect, &oldprotect); 50 | } -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CErrorDialog.cs: -------------------------------------------------------------------------------- 1 | using Refract.UI.Core.Interfaces; 2 | using Refract.UI.Core.Singletons; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel; 6 | using System.Data; 7 | using System.Drawing; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace SMC.UI.Core.Controls 14 | { 15 | public partial class CErrorDialog : Form, IThemeableControl 16 | { 17 | public CErrorDialog(string title, string description) 18 | { 19 | InitializeComponent(); 20 | UIThemeManager.OnThemeChanged(this, OnThemeChanged_Implementation); 21 | this.SetThemeAware(); 22 | MaximizeBox = true; 23 | MinimizeBox = true; 24 | Text = title; 25 | InnerForm.TitleBarTitle = title; 26 | ErrorRTB.Text = description; 27 | } 28 | 29 | private void OnThemeChanged_Implementation(UIThemeInfo themeData) 30 | { 31 | return; 32 | } 33 | 34 | public IEnumerable GetThemedControls() 35 | { 36 | yield return InnerForm; 37 | yield return ErrorRTB; 38 | yield return AcceptButton; 39 | } 40 | 41 | private void AcceptButton_Click(object sender, EventArgs e) 42 | { 43 | Close(); 44 | } 45 | 46 | private void button1_Click(object sender, EventArgs e) 47 | { 48 | 49 | } 50 | 51 | public static void Show(string title, string description, bool topMost = false) 52 | { 53 | new CErrorDialog(title, description) { TopMost = topMost }.ShowDialog(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /TreyarchCompiler/Utilities/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace TreyarchCompiler.Utilities 6 | { 7 | internal static class Extensions 8 | { 9 | private static readonly Random rng = new Random(); 10 | 11 | public static void Replace(this List list, int index, List input) 12 | { 13 | list.RemoveRange(index, input.Count); 14 | list.InsertRange(index, input); 15 | } 16 | 17 | public static byte[] ToByteArray(this short[] arr, Enums.Games game) 18 | { 19 | if(game == Enums.Games.T6) 20 | return arr.Select(Convert.ToByte).ToArray(); 21 | 22 | var bytes = new List(); 23 | foreach (var value in arr) 24 | bytes.AddRange(BitConverter.GetBytes(value)); 25 | return bytes.ToArray(); 26 | } 27 | 28 | public static void Shuffle(this IList list) 29 | { 30 | var n = list.Count; 31 | while (n > 1) 32 | { 33 | n--; 34 | var k = rng.Next(n + 1); 35 | var value = list[k]; 36 | list[k] = list[n]; 37 | list[n] = value; 38 | } 39 | } 40 | 41 | public static ushort[] GetRandomArray(int size, ushort start, ushort end) 42 | { 43 | var unique = new List(); 44 | while(unique.Count < size) 45 | { 46 | var value = (ushort)rng.Next(start, end); 47 | 48 | if(!unique.Contains(value)) 49 | unique.Add(value); 50 | } 51 | return unique.ToArray(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /t8cinternal/builtins.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | #include 4 | 5 | struct alignas(8) BuiltinFunctionDef 6 | { 7 | int canonId; 8 | int min_args; 9 | int max_args; 10 | void* actionFunc; 11 | int type; 12 | }; 13 | 14 | inline uint32_t t8hash(const char* key) { 15 | 16 | const char* data = key; 17 | uint32_t hash = 0x4B9ACE2F; 18 | 19 | while(*data) 20 | { 21 | char c = tolower(*data); 22 | hash = ((c + hash) ^ ((c + hash) << 10)) + (((c + hash) ^ ((c + hash) << 10)) >> 6); 23 | data++; 24 | } 25 | 26 | return 0x8001 * ((9 * hash) ^ ((9 * hash) >> 11)); 27 | } 28 | 29 | typedef INT64(__fastcall* tScrVm_GetInt)(unsigned int inst, unsigned int index); 30 | typedef char*(__fastcall* tScrVm_GetString)(unsigned int inst, unsigned int index); 31 | typedef INT64(__fastcall* tScrVm_GetNumParam)(unsigned int inst); 32 | typedef INT64(__fastcall* tScrVm_AddInt)(unsigned int inst, int64_t value); 33 | typedef INT64(__fastcall* tScrVm_AddBool)(unsigned int inst, bool value); 34 | 35 | class GSCBuiltins 36 | { 37 | public: 38 | static void Init(); 39 | static void AddCustomFunction(const char* name, void* funcPtr); 40 | static tScrVm_GetInt ScrVm_GetInt; 41 | static tScrVm_GetString ScrVm_GetString; 42 | static tScrVm_GetNumParam ScrVm_GetNumParam; 43 | static tScrVm_AddInt ScrVm_AddInt; 44 | static tScrVm_AddBool ScrVm_AddBool; 45 | 46 | private: 47 | static INT64 Exec(int scriptInst); 48 | static void Generate(); 49 | static std::unordered_map CustomFunctions; 50 | 51 | private: 52 | static void GScr_nprintln(int scriptInst); 53 | static void GScr_detour(int scriptInst); 54 | static void GScr_relinkDetours(int scriptInst); 55 | static void GScr_livesplit(int scriptInst); 56 | 57 | public: 58 | static void nlog(const char* str, ...); 59 | }; -------------------------------------------------------------------------------- /TreyarchCompiler/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /t7cinternal/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | // Windows Header Files 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define SystemHandleInformation 16 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #define NT_SUCCESS(x) ((x) >= 0) 22 | #define STATUS_INFO_LENGTH_MISMATCH 0xc0000004 23 | 24 | #define SystemHandleInformation 16 25 | #define ObjectBasicInformation 0 26 | #define ObjectNameInformation 1 27 | #define ObjectTypeInformation 2 28 | #define EXPORT extern "C" __declspec(dllexport) 29 | 30 | constexpr uint32_t fnv_base_32 = 0x4B9ACE2F; 31 | 32 | inline uint32_t fnv1a(const char* key) { 33 | 34 | const char* data = key; 35 | uint32_t hash = 0x4B9ACE2F; 36 | while (*data) 37 | { 38 | hash ^= *data; 39 | hash *= 0x1000193; 40 | data++; 41 | } 42 | hash *= 0x1000193; // bo3 wtf lol 43 | return hash; 44 | 45 | } 46 | 47 | template void chgmem(__int64 addy, T copy) 48 | { 49 | DWORD oldprotect; 50 | VirtualProtect((void*)addy, sizeof(T), PAGE_EXECUTE_READWRITE, &oldprotect); 51 | *(T*)addy = copy; 52 | VirtualProtect((void*)addy, sizeof(T), oldprotect, &oldprotect); 53 | } 54 | 55 | void chgmem(__int64 addy, __int32 size, void* copy); 56 | 57 | extern const char MSELECT[]; 58 | 59 | #define IS_WINSTORE (*(uint8_t*)(MSELECT + 0xC) == (uint8_t)0xd0) 60 | #define OFFSET_S(off) (*(uint64_t*)((uint64_t)(NtCurrentTeb()->ProcessEnvironmentBlock) + 0x10) + (uint64_t)off) 61 | #define REBASE(steam, msstore) ((uint64_t(__fastcall*)(uint64_t, uint64_t))(char*)MSELECT)(steam, msstore) -------------------------------------------------------------------------------- /t7cinternal/offsets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | #include 4 | 5 | // dont mess with these because when I add new games, these macros will change 6 | 7 | #define OFF_IsProfileBuild REBASE(0x32D7D70, 0x31154A0) 8 | #define OFF_ScrVm_GetInt REBASE(0x12EB7F0, 0x1391240) 9 | #define OFF_ScrVm_GetString REBASE(0x12EBAA0, 0x1391970) 10 | #define OFF_ScrVm_Opcodes REBASE(0x32E6350, 0x2EB38B0) 11 | #define OFF_ScrVm_Opcodes2 REBASE(0x3306350, 0x2E838B0) 12 | #define OFF_Scr_GetFunction REBASE(0x1AF7820, NULL) 13 | #define OFF_GetMethod REBASE(NULL, 0x136CD40) 14 | #define OFF_Scr_GetMethod REBASE(0x1AF79B0, NULL) 15 | #define OFF_DB_FindXAssetHeader REBASE(0x1420ED0, 0x14DC380) 16 | #define XASSETTYPE_SCRIPTPARSETREE 0x36u 17 | #define OFF_s_runningUILevel REBASE(0x168ED91E, 0x148FD0EF) 18 | #define OFF_Scr_GscObjLink REBASE(0x12CC300, 0x1370AC0) 19 | #define OFF_ScrVar_AllocVariableInternal REBASE(0x12D9A60, 0x137F050) 20 | #define OFF_ScrVm_GetFunc REBASE(0x12EB730, 0x1392030) 21 | #define PTR_sSessionModeState REBASE(0x168ED7F4, 0x18AE65C4) 22 | #define GSCR_FASTEXIT REBASE(0x2C53903, NULL) 23 | #define OFF_BID_Scr_CastInt REBASE(0x32D71A0, 0x31148E0) 24 | #define OFF_Scr_CastInt REBASE(0x162E60, 0x1F1EF0) 25 | #define OFF_ScrVarGlob REBASE(0x51A3500, 0x3F66900) 26 | 27 | #define OFF_VM_OP_GetAPIFunction REBASE(0x12D0890, 0x1374E90) 28 | #define OFF_VM_OP_GetFunction REBASE(0x12D0A30, 0x1374E50) 29 | #define OFF_VM_OP_ScriptFunctionCall REBASE(0x12CEE80, 0x1372F80) 30 | #define OFF_VM_OP_ScriptMethodCall REBASE(0x12CF1D0, 0x1373320) 31 | #define OFF_VM_OP_ScriptThreadCall REBASE(0x12CFB10, 0x13735F0) 32 | #define OFF_VM_OP_ScriptMethodThreadCall REBASE(0x12CF570, 0x1373A20) 33 | #define OFF_VM_OP_CallBuiltin REBASE(0x12CE460, 0x1372CB0) 34 | #define OFF_VM_OP_CallBuiltinMethod REBASE(0x12CE3A0, 0x1372D20) -------------------------------------------------------------------------------- /T8CompilerLib/ScriptComponents/T89ScriptSection.cs: -------------------------------------------------------------------------------- 1 | namespace T89CompilerLib.ScriptComponents 2 | { 3 | public abstract class T89ScriptSection 4 | { 5 | public T89ScriptSection NextSection { get; private set; } 6 | public T89ScriptSection PreviousSection { get; private set; } 7 | 8 | public abstract uint Size(); 9 | 10 | public abstract ushort Count(); 11 | 12 | public abstract byte[] Serialize(); 13 | 14 | public abstract void UpdateHeader(ref T89ScriptHeader Header); 15 | 16 | public uint GetScriptEnd() 17 | { 18 | return Size() + (NextSection?.GetScriptEnd() ?? 0u); 19 | } 20 | 21 | public uint GetBaseAddress() 22 | { 23 | if (PreviousSection == null) 24 | return 0; 25 | 26 | return PreviousSection.GetSectionEnd(); 27 | } 28 | 29 | public uint GetSectionEnd() 30 | { 31 | if (PreviousSection == null) 32 | return Size(); 33 | 34 | return Size() + PreviousSection.GetSectionEnd(); 35 | } 36 | 37 | internal void Link(T89ScriptSection previous, T89ScriptSection next) 38 | { 39 | NextSection = next; 40 | PreviousSection = previous; 41 | } 42 | 43 | public virtual void Commit(ref byte[] RawData, ref T89ScriptHeader Header) 44 | { 45 | byte[] LocalData = Serialize(); 46 | 47 | byte[] NewBuffer = new byte[LocalData.Length + RawData.Length]; 48 | 49 | RawData.CopyTo(NewBuffer, 0); 50 | LocalData.CopyTo(NewBuffer, RawData.Length); 51 | 52 | RawData = NewBuffer; 53 | 54 | UpdateHeader(ref Header); 55 | NextSection?.Commit(ref RawData, ref Header); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_GetFuncPtr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using T7CompilerLib.ScriptComponents; 8 | 9 | namespace T7CompilerLib.OpCodes 10 | { 11 | public sealed class T7OP_GetFuncPtr : T7OP_AbstractCall 12 | { 13 | internal T7OP_GetFuncPtr(T7Import import, EndianType endianess): base(endianess) 14 | { 15 | Code = ScriptOpCode.GetFunction; 16 | Import = import; 17 | } 18 | 19 | protected override byte[] Serialize(ushort EmissionValue) 20 | { 21 | byte[] data = new byte[GetSize()]; 22 | 23 | base.Serialize(EmissionValue).CopyTo(data, 0); 24 | 25 | uint WriteAddress = 0u; 26 | 27 | if (Endianess == EndianType.LittleEndian) 28 | WriteAddress = (GetCommitDataAddress()).AlignValue(0x8) - CommitAddress; 29 | else 30 | WriteAddress = (GetCommitDataAddress()).AlignValue(0x4) - CommitAddress; 31 | 32 | Import.Function.GetBytes(Endianess).CopyTo(data, WriteAddress); 33 | 34 | return data; 35 | } 36 | 37 | public override uint GetCommitDataAddress() 38 | { 39 | return CommitAddress + T7OP_SIZE; 40 | } 41 | 42 | //OP_CODE 0x2 43 | //NUMPARAMS 0x1 44 | //padding 0x1 45 | //QWORD ALIGN 46 | //Function 47 | //0 (x4) 48 | public override uint GetSize() 49 | { 50 | if (Endianess == EndianType.LittleEndian) 51 | return (GetCommitDataAddress()).AlignValue(0x8) + 4 + 4 - CommitAddress; 52 | 53 | return (GetCommitDataAddress()).AlignValue(0x4) + 4 - CommitAddress; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /External/Reference/x64hijackasm.txt: -------------------------------------------------------------------------------- 1 | // adjust the stack and emplace original rip 2 | sub rsp, 0x8 3 | mov DWORD PTR[rsp], 0xdeadbeef 4 | mov DWORD PTR[rsp+0x4], 0xdeadbeef 5 | 6 | // save vars 7 | PUSHFQ 8 | push rax 9 | push rcx 10 | push rdx 11 | push rbx 12 | push rsp 13 | push rbp 14 | push rsi 15 | push rdi 16 | push r8 17 | push r9 18 | push r10 19 | push r11 20 | push r12 21 | push r13 22 | push r14 23 | push r15 24 | 25 | // push stored xmm ptr 26 | mov rax, 0xdeadbeefdeadbeef 27 | movapd [rax], xmm0 28 | movapd [rax + 0x10], xmm1 29 | movapd [rax + 0x20], xmm2 30 | movapd [rax + 0x30], xmm3 31 | movapd [rax + 0x40], xmm4 32 | movapd [rax + 0x50], xmm5 33 | movapd [rax + 0x60], xmm6 34 | movapd [rax + 0x70], xmm7 35 | movapd [rax + 0x80], xmm8 36 | movapd [rax + 0x90], xmm9 37 | movapd [rax + 0xA0], xmm10 38 | movapd [rax + 0xB0], xmm11 39 | movapd [rax + 0xC0], xmm12 40 | movapd [rax + 0xD0], xmm13 41 | movapd [rax + 0xE0], xmm14 42 | movapd [rax + 0xF0], xmm15 43 | 44 | // make the call 45 | mov rax, 0xdeadbeefdeadbeef 46 | call rax 47 | 48 | // push stored xmm ptr 49 | mov rax, 0xdeadbeefdeadbeef 50 | movapd xmm0, [rax] 51 | movapd xmm1, [rax + 0x10] 52 | movapd xmm2, [rax + 0x20] 53 | movapd xmm3, [rax + 0x30] 54 | movapd xmm4, [rax + 0x40] 55 | movapd xmm5, [rax + 0x50] 56 | movapd xmm6, [rax + 0x60] 57 | movapd xmm7, [rax + 0x70] 58 | movapd xmm8, [rax + 0x80] 59 | movapd xmm9, [rax + 0x90] 60 | movapd xmm10, [rax + 0xa0] 61 | movapd xmm11, [rax + 0xb0] 62 | movapd xmm12, [rax + 0xc0] 63 | movapd xmm13, [rax + 0xd0] 64 | movapd xmm14, [rax + 0xe0] 65 | movapd xmm15, [rax + 0xf0] 66 | 67 | // restore vars 68 | pop r15 69 | pop r14 70 | pop r13 71 | pop r12 72 | pop r11 73 | pop r10 74 | pop r9 75 | pop r8 76 | pop rdi 77 | pop rsi 78 | pop rbp 79 | pop rsp 80 | pop rbx 81 | pop rdx 82 | pop rcx 83 | pop rax 84 | POPFQ 85 | 86 | // exit this hoe 87 | ret -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_Call.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using T89CompilerLib.ScriptComponents; 3 | 4 | namespace T89CompilerLib.OpCodes 5 | { 6 | public sealed class T89OP_Call : T89OP_AbstractCall 7 | { 8 | internal T89OP_Call(T89Import import, uint context) 9 | { 10 | if (context.HasContext(ScriptContext.HasCaller)) 11 | { 12 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptMethodThreadCall : ScriptOpCode.ScriptMethodCall; 13 | } 14 | else 15 | { 16 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptThreadCall : ScriptOpCode.ScriptFunctionCall; 17 | } 18 | Import = import; 19 | } 20 | 21 | protected override byte[] Serialize(ushort EmissionValue) 22 | { 23 | byte[] data = new byte[GetSize()]; 24 | 25 | base.Serialize(EmissionValue).CopyTo(data, 0); 26 | 27 | data[2] = Import.NumParams; 28 | data[3] = Import.Flags; 29 | 30 | uint WriteAddress = (GetCommitDataAddress() + 2).AlignValue(0x8) - CommitAddress; 31 | 32 | BitConverter.GetBytes(Import.Function).CopyTo(data, WriteAddress); 33 | //BitConverter.GetBytes(Import.Namespace).CopyTo(data, WriteAddress + 4); 34 | return data; 35 | } 36 | 37 | public override uint GetCommitDataAddress() 38 | { 39 | return CommitAddress + T89OP_SIZE; 40 | } 41 | 42 | //OP_CODE 0x2 43 | //NUMPARAMS 0x1 44 | //padding 0x1 45 | //QWORD ALIGN 46 | //Function 47 | //0 (x4) 48 | public override uint GetSize() 49 | { 50 | return (GetCommitDataAddress() + 1 + 1).AlignValue(0x8) + 4 + 4 - CommitAddress; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /t8cinternal/LazyLink.cpp: -------------------------------------------------------------------------------- 1 | #include "LazyLink.h" 2 | #include "offsets.h" 3 | #include "detours.h" 4 | #include "builtins.h" 5 | 6 | void LazyLink::Init() 7 | { 8 | // Change Opcode Handler 0x16 to VM_OP_GetLazyFunction 9 | *(INT64*)(0x16 * 8 + OFF_ScrVm_Opcodes) = (INT64)VM_OP_GetLazyFunction; 10 | } 11 | 12 | void LazyLink::VM_OP_GetLazyFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate) 13 | { 14 | //INT64 base = (*fs_0 + 3) & 0xFFFFFFFFFFFFFFFCLL; 15 | //INT32 Namespace = *(INT32*)base; 16 | //INT32 Function = *(INT32*)(base + 4); 17 | //char* script = (char*)(*fs_0 + (*(INT32*)(base + 8))); 18 | //auto asset = ScriptDetours::FindScriptParsetree(script); 19 | 20 | //if (!asset) 21 | //{ 22 | // *(INT32*)(fs_0[1] + 0x18) = 0x0; // undefined 23 | // fs_0[1] += 0x10; // change stack top 24 | // return; 25 | //} 26 | 27 | //auto buffer = *(char**)(asset + 0x10); 28 | //auto exportsOffset = *(INT32*)(buffer + 0x20); 29 | //auto exports = (INT64)(exportsOffset + buffer); 30 | //auto numExports = *(INT16*)(buffer + 0x3A); 31 | //__t7export* currentExport = (__t7export*)exports; 32 | //bool found = false; 33 | 34 | //for (INT16 i = 0; i < numExports; i++, currentExport++) 35 | //{ 36 | // if (currentExport->funcName != Function) 37 | // { 38 | // continue; 39 | // } 40 | // if (currentExport->funcNS != Namespace) 41 | // { 42 | // continue; 43 | // } 44 | // found = true; 45 | // break; 46 | //} 47 | 48 | //if (!found) 49 | //{ 50 | // *(INT32*)(fs_0[1] + 0x18) = 0x0; // undefined 51 | // fs_0[1] += 0x10; // change stack top 52 | // return; 53 | //} 54 | 55 | //*(INT32*)(fs_0[1] + 0x18) = 0xE; // assign the top variable's type 56 | //*(INT64*)(fs_0[1] + 0x10) = (INT64)buffer + currentExport->bytecodeOffset; // assign the top variable's value 57 | //fs_0[1] += 0x10; // change stack top 58 | //*fs_0 = base + 0xC; // move past the data 59 | } 60 | -------------------------------------------------------------------------------- /t8cinternal/t8cinternal.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | -------------------------------------------------------------------------------- /T7CompilerLib/ScriptComponents/T7ScriptSection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace T7CompilerLib.ScriptComponents 8 | { 9 | public abstract class T7ScriptSection 10 | { 11 | public T7ScriptSection NextSection { get; private set; } 12 | public T7ScriptSection PreviousSection { get; private set; } 13 | 14 | public abstract uint Size(); 15 | 16 | public abstract ushort Count(); 17 | 18 | public abstract byte[] Serialize(); 19 | 20 | public abstract void UpdateHeader(ref T7ScriptHeader Header); 21 | 22 | public uint GetScriptEnd() 23 | { 24 | return Size() + (NextSection?.GetScriptEnd() ?? 0u); 25 | } 26 | 27 | public uint GetBaseAddress() 28 | { 29 | if (PreviousSection == null) 30 | return 0; 31 | 32 | return PreviousSection.GetSectionEnd(); 33 | } 34 | 35 | public uint GetSectionEnd() 36 | { 37 | if (PreviousSection == null) 38 | return Size(); 39 | 40 | return Size() + PreviousSection.GetSectionEnd(); 41 | } 42 | 43 | internal void Link(T7ScriptSection previous, T7ScriptSection next) 44 | { 45 | NextSection = next; 46 | PreviousSection = previous; 47 | } 48 | 49 | public virtual void Commit(ref byte[] RawData, ref T7ScriptHeader Header) 50 | { 51 | byte[] LocalData = Serialize(); 52 | 53 | byte[] NewBuffer = new byte[LocalData.Length + RawData.Length]; 54 | 55 | RawData.CopyTo(NewBuffer, 0); 56 | LocalData.CopyTo(NewBuffer, RawData.Length); 57 | 58 | RawData = NewBuffer; 59 | 60 | UpdateHeader(ref Header); 61 | NextSection?.Commit(ref RawData, ref Header); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /TreyarchCompiler/Compiler.cs: -------------------------------------------------------------------------------- 1 | using TreyarchCompiler.Enums; 2 | using TreyarchCompiler.Games; 3 | using TreyarchCompiler.Interface; 4 | using TreyarchCompiler.Utilities; 5 | 6 | namespace TreyarchCompiler 7 | { 8 | //NOTE: this class system will no longer work as of bo3, because each platform has unique opcodes. 9 | public class Compiler 10 | { 11 | public static CompiledCode Compile(Platforms platform, Enums.Games game, Modes mode, bool uset8masking, string code, string path = "") 12 | { 13 | switch(platform) 14 | { 15 | case Platforms.PC: 16 | return CompilePC(game, mode, code, path, uset8masking)?.Compile(); 17 | 18 | case Platforms.Xbox: 19 | case Platforms.PS3: 20 | return CompileConsole(game, mode, code, path)?.Compile(); 21 | } 22 | return null; 23 | } 24 | 25 | public static CompiledCode CompileRCE(Platforms platform, Enums.Games game, Modes mode, string code, string address, string path = "") 26 | { 27 | return null; 28 | } 29 | 30 | private static ICompiler CompilePC(Enums.Games game, Modes mode, string code, string path, bool uset8masking) 31 | { 32 | switch(game) 33 | { 34 | case Enums.Games.T7: 35 | return new GSCCompiler(mode, code, path, Platforms.PC, game, false); 36 | case Enums.Games.T8: 37 | return new T89Compiler(game, code); 38 | } 39 | return null; 40 | } 41 | 42 | private static ICompiler CompilePS4(Enums.Games game, Modes mode, string code, string path, bool uset8masking) 43 | { 44 | return null; 45 | } 46 | 47 | private static ICompiler CompileConsole(Enums.Games game, Modes mode, string code, string path) 48 | { 49 | return null; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /External/PointerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using static System.EnvironmentEx; 7 | 8 | namespace System 9 | { 10 | public static class PointerExtensions 11 | { 12 | public static IntPtr Add(this IntPtr i, IntPtr offset) 13 | { 14 | if (IntPtr.Size == sizeof(int)) return IntPtr.Add(i, offset.ToInt32()); 15 | return new IntPtr(i.ToInt64() + offset.ToInt64()); 16 | } 17 | 18 | public static PointerEx Add(this PointerEx i, PointerEx offset) 19 | { 20 | return i.IntPtr.Add(offset); 21 | } 22 | 23 | public static IntPtr Subtract(this IntPtr i, IntPtr offset) 24 | { 25 | if (IntPtr.Size == sizeof(int)) return IntPtr.Subtract(i, offset.ToInt32()); 26 | return new IntPtr(i.ToInt64() - offset.ToInt64()); 27 | } 28 | 29 | public static PointerEx Subtract(this PointerEx i, PointerEx offset) 30 | { 31 | return i.IntPtr.Subtract(offset); 32 | } 33 | 34 | public static PointerEx Align(this PointerEx value, uint alignment) => (value + (alignment - 1)) & ~(alignment - 1); 35 | 36 | public static PointerEx ToPointer(this byte[] data) 37 | { 38 | if (IntPtr.Size < data.Length) 39 | { 40 | throw new InvalidCastException(DSTR(DSTR_PTR_CAST_FAIL, data.Length, IntPtr.Size)); 41 | } 42 | 43 | if(data.Length < IntPtr.Size) 44 | { 45 | byte[] _data = new byte[IntPtr.Size]; 46 | data.CopyTo(_data, 0); 47 | data = _data; 48 | } 49 | 50 | if (IntPtr.Size == sizeof(long)) 51 | { 52 | return BitConverter.ToInt64(data, 0); 53 | } 54 | 55 | return BitConverter.ToInt32(data, 0); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_GetLocalFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public sealed class T7OP_GetLocalFunction : T7OpCode 11 | { 12 | /// 13 | /// The opcode this jump should jump past 14 | /// 15 | public T7OpCode After; 16 | 17 | internal T7OP_GetLocalFunction(ScriptOpCode code, EndianType endianess) : base(endianess) 18 | { 19 | Code = code; 20 | } 21 | 22 | protected override byte[] Serialize(ushort EmissionValue) 23 | { 24 | byte[] data = new byte[GetSize()]; 25 | 26 | base.Serialize(EmissionValue).CopyTo(data, 0); 27 | 28 | //This is just for identification of mis-written jumps in the output binary (if there are any) 29 | data[data.Length - 1] = 0xFF; 30 | data[data.Length - 2] = 0xFF; 31 | data[data.Length - 3] = 0xFF; 32 | data[data.Length - 4] = 0xFF; 33 | 34 | return data; 35 | } 36 | 37 | internal void CommitJump(ref byte[] data) 38 | { 39 | if (After == null) 40 | throw new NotImplementedException("A GetLocalFunction was recorded, but the opcode to jump to was never set..."); 41 | 42 | uint JumpTo = After.CommitAddress + After.GetSize(); 43 | uint JumpFrom = CommitAddress + GetSize(); 44 | 45 | ((int)(JumpTo - JumpFrom)).GetBytes(Endianess).CopyTo(data, GetCommitDataAddress()); 46 | } 47 | 48 | public override uint GetCommitDataAddress() 49 | { 50 | return (CommitAddress + T7OP_SIZE).AlignValue(0x4); 51 | } 52 | 53 | public override uint GetSize() 54 | { 55 | return GetCommitDataAddress() + 4 - CommitAddress; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /t7cinternal/t7cinternal.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | -------------------------------------------------------------------------------- /External/PEStructures/PEDataDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.PortableExecutable; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace System.PEStructures 9 | { 10 | public abstract class PEDataDirectory 11 | { 12 | public int DirectoryOffset { get; } 13 | public PEHeaders Headers { get; } 14 | public Memory ImageData { get; } 15 | public bool IsValid { get; } 16 | 17 | private protected PEDataDirectory(PEHeaders headers, Memory imageData, DirectoryEntry directory) 18 | { 19 | if (headers == null || headers.PEHeader == null) throw new ArgumentException("Attempted to initialize a PE data directory with null headers"); 20 | IsValid = headers.TryGetDirectoryOffset(directory, out var directoryOffset); 21 | DirectoryOffset = directoryOffset; 22 | Headers = headers; 23 | ImageData = imageData; 24 | } 25 | 26 | public int RelativeToOffset(int rva) 27 | { 28 | var sectionHeader = Headers.SectionHeaders[Headers.GetContainingSectionIndex(rva)]; 29 | return rva - sectionHeader.VirtualAddress + sectionHeader.PointerToRawData; 30 | } 31 | 32 | private protected int VirtualToRelative(int va) 33 | { 34 | return va - (int)Headers.PEHeader.ImageBase; // headers wont ever be null because we prevent it in the constructor 35 | } 36 | 37 | private protected int VirtualToRelative(long va) 38 | { 39 | return VirtualToRelative((int)va); 40 | } 41 | 42 | internal int GetPtrFromRVA(int rva, PointerEx imageBase) 43 | { 44 | PointerEx delta; 45 | 46 | var sectionHeader = Headers.SectionHeaders[Headers.GetContainingSectionIndex(rva)]; 47 | delta = (sectionHeader.VirtualAddress - sectionHeader.PointerToRawData); 48 | return (imageBase + rva - delta); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /External/Quartz/QAsm/QCodeBlock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Quartz.QAsm.Instructions; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace System.Quartz.QAsm 9 | { 10 | public class QCodeBlock : QInstruction 11 | { 12 | private List Instructions; 13 | private QInstruction LastInstruction; 14 | private QInstruction FirstInstruction; 15 | private List ScopedVariables; 16 | private QVariable[] Parameters; 17 | 18 | /// 19 | /// Context string is the full path context identifier for this block 20 | /// 21 | public readonly string Context; 22 | public QCodeBlock(string context) 23 | { 24 | Context = context; 25 | Instructions = new List(); 26 | ScopedVariables = new List(); 27 | } 28 | 29 | public void SetParameters(QVariable[] parameters) 30 | { 31 | if (parameters != null) 32 | { 33 | ScopedVariables.AddRange(parameters); 34 | Parameters = new QVariable[parameters.Length]; 35 | parameters.CopyTo(Parameters, 0); 36 | } 37 | } 38 | 39 | public void Add(QInstruction instruction) 40 | { 41 | if(instruction is null) 42 | { 43 | throw new ArgumentException($"{nameof(instruction)} cannot be null"); 44 | } 45 | if(FirstInstruction is null) 46 | { 47 | FirstInstruction = instruction; 48 | LastInstruction = instruction; 49 | } 50 | else 51 | { 52 | LastInstruction.Link(instruction); 53 | LastInstruction = instruction; 54 | } 55 | instruction.ParentBlock = this; 56 | } 57 | 58 | public void AddScopedParameter(QVariable variable) 59 | { 60 | ScopedVariables.Add(variable); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_Call.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using T7CompilerLib.ScriptComponents; 8 | 9 | namespace T7CompilerLib.OpCodes 10 | { 11 | public sealed class T7OP_Call : T7OP_AbstractCall 12 | { 13 | internal T7OP_Call(T7Import import, uint context, EndianType endianess) : base(endianess) 14 | { 15 | if (context.HasContext(ScriptContext.HasCaller)) 16 | { 17 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptMethodThreadCall : ScriptOpCode.ScriptMethodCall; 18 | } 19 | else 20 | { 21 | Code = context.HasContext(ScriptContext.Threaded) ? ScriptOpCode.ScriptThreadCall : (context.HasContext(ScriptContext.IsDebug) ? ScriptOpCode.CallBuiltin: ScriptOpCode.ScriptFunctionCall); 22 | } 23 | Import = import; 24 | } 25 | 26 | protected override byte[] Serialize(ushort EmissionValue) 27 | { 28 | byte[] data = new byte[GetSize()]; 29 | 30 | // base.Serialize(EmissionValue).CopyTo(data, 0); 31 | 32 | data[T7OP_SIZE] = Import.NumParams; 33 | 34 | if(Endianess == EndianType.LittleEndian) 35 | data[3] = Import.Flags; 36 | 37 | uint WriteAddress = (GetCommitDataAddress() + T7OP_SIZE).AlignValue(T7OP_SIZE * 4) - CommitAddress; 38 | 39 | Import.Function.GetBytes(Endianess).CopyTo(data, WriteAddress); 40 | 41 | return data; 42 | } 43 | 44 | public override uint GetCommitDataAddress() 45 | { 46 | return CommitAddress + T7OP_SIZE; 47 | } 48 | 49 | //OP_CODE 0x2 50 | //NUMPARAMS 0x1 51 | //padding 0x1 52 | //QWORD ALIGN 53 | //Function 54 | //0 (x4) 55 | public override uint GetSize() 56 | { 57 | return (GetCommitDataAddress() + T7OP_SIZE).AlignValue(T7OP_SIZE * 4) + (T7OP_SIZE * 4) - CommitAddress; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_GetString.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using T7CompilerLib.ScriptComponents; 8 | 9 | //Class should be finished. 10 | namespace T7CompilerLib.OpCodes 11 | { 12 | public sealed class T7OP_GetString : T7OpCode 13 | { 14 | private T7StringTableEntry __ref__; 15 | public T7StringTableEntry ReferencedString 16 | { 17 | get => __ref__; 18 | private set 19 | { 20 | __ref__?.References.Remove(this); 21 | __ref__ = value; 22 | __ref__?.References.Add(this); 23 | } 24 | } 25 | 26 | public T7OP_GetString(ScriptOpCode op_info, T7StringTableEntry refstring, EndianType endianess) : base(op_info, endianess) 27 | { 28 | ReferencedString = refstring; 29 | } 30 | 31 | protected override byte[] Serialize(ushort EmissionValue) 32 | { 33 | byte[] data = new byte[GetSize()]; 34 | 35 | base.Serialize(EmissionValue).CopyTo(data, 0); 36 | 37 | //We dont need to pass a real pointer here. Game overwrites it on load anyways 38 | if(Endianess == EndianType.LittleEndian) 39 | new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }.CopyTo(data, GetCommitDataAddress() - CommitAddress); 40 | else 41 | new byte[] { 0xFF, 0xFF }.CopyTo(data, GetCommitDataAddress() - CommitAddress); 42 | 43 | return data; 44 | } 45 | 46 | public override uint GetCommitDataAddress() 47 | { 48 | if (Endianess == EndianType.LittleEndian) 49 | return (CommitAddress + T7OP_SIZE).AlignValue(0x4); 50 | 51 | return (CommitAddress + T7OP_SIZE).AlignValue(0x2); 52 | } 53 | 54 | public override uint GetSize() 55 | { 56 | if (Endianess == EndianType.LittleEndian) 57 | return 4 + GetCommitDataAddress() - CommitAddress; 58 | return 2 + GetCommitDataAddress() - CommitAddress; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /External/PEStructures/PELoadConfigDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.PortableExecutable; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace System.PEStructures 10 | { 11 | public class PELoadConfigDirectory : PEDataDirectory 12 | { 13 | public PELoadConfigDirectory(PEHeaders headers, Memory imageData) : base(headers, imageData, headers.PEHeader.LoadConfigTableDirectory) { } 14 | 15 | public (int HandlerCount, int RelativeAddress) GetExceptionTable() 16 | { 17 | if (!IsValid || Headers.PEHeader.DllCharacteristics.HasFlag(DllCharacteristics.NoSeh)) return (-1, -1); 18 | var loadConfigDirectory = MemoryMarshal.Read(ImageData.Span.Slice(DirectoryOffset)); 19 | return (loadConfigDirectory.SEHandlerCount, VirtualToRelative(loadConfigDirectory.SEHandlerTable)); 20 | } 21 | 22 | public int GetSecurityCookieRvA() 23 | { 24 | if (!IsValid) return 0; 25 | long cookie; 26 | if (Headers.PEHeader.Magic == PEMagic.PE32) cookie = MemoryMarshal.Read(ImageData.Span.Slice(DirectoryOffset).ToArray()).lpSecurityCookie; 27 | else cookie = MemoryMarshal.Read(ImageData.Span.Slice(DirectoryOffset).ToArray()).lpSecurityCookie; 28 | return cookie == 0 ? 0 : VirtualToRelative(cookie); 29 | } 30 | } 31 | 32 | [StructLayout(LayoutKind.Explicit, Size = 164)] 33 | public readonly struct PEImageLoadConfigDirectory32 34 | { 35 | [FieldOffset(0x3C)] 36 | public readonly int lpSecurityCookie; 37 | 38 | [FieldOffset(0x40)] 39 | public readonly int SEHandlerTable; 40 | 41 | [FieldOffset(0x44)] 42 | public readonly int SEHandlerCount; 43 | } 44 | 45 | [StructLayout(LayoutKind.Explicit, Size = 264)] 46 | public readonly struct PEImageLoadConfigDirectory64 47 | { 48 | [FieldOffset(0x58)] 49 | public readonly long lpSecurityCookie; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_LazyGetFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using T7CompilerLib.ScriptComponents; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public class T7OP_LazyGetFunction : T7OpCode 11 | { 12 | private uint Namespace; 13 | private uint Function; 14 | 15 | private T7StringTableEntry __ref__; 16 | public T7StringTableEntry ReferencedString 17 | { 18 | get => __ref__; 19 | private set 20 | { 21 | __ref__?.LazyReferences.Remove(this); 22 | __ref__ = value; 23 | __ref__?.LazyReferences.Add(this); 24 | } 25 | } 26 | 27 | internal T7OP_LazyGetFunction(uint ns, uint func, T7StringTableEntry refstring) : base(System.IO.EndianType.LittleEndian) 28 | { 29 | Code = ScriptOpCode.LazyGetFunction; 30 | ReferencedString = refstring; 31 | Namespace = ns; 32 | Function = func; 33 | } 34 | 35 | protected override byte[] Serialize(ushort EmissionValue) 36 | { 37 | byte[] data = new byte[GetSize()]; 38 | 39 | base.Serialize(EmissionValue).CopyTo(data, 0); 40 | 41 | uint WriteAddress = GetCommitDataAddress().AlignValue(0x4) - CommitAddress; 42 | 43 | Namespace.GetBytes(Endianess).CopyTo(data, WriteAddress); 44 | Function.GetBytes(Endianess).CopyTo(data, WriteAddress + 0x4); 45 | // script name offset will be fixed up here which is: distance from instruction pointer after passing opcode 46 | 47 | return data; 48 | } 49 | 50 | public override uint GetCommitDataAddress() 51 | { 52 | return CommitAddress + T7OP_SIZE; 53 | } 54 | 55 | //OP_CODE 0x2 56 | //NUMPARAMS 0x1 57 | //padding 0x1 58 | //QWORD ALIGN 59 | //Function 60 | //0 (x4) 61 | public override uint GetSize() 62 | { 63 | return (GetCommitDataAddress()).AlignValue(0x4) + (4 * 3) - CommitAddress; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /External/PEStructures/PETlsDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.PortableExecutable; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace System.PEStructures 10 | { 11 | public class PETlsDirectory : PEDataDirectory 12 | { 13 | public PETlsDirectory(PEHeaders headers, Memory imageData) : base(headers, imageData, headers.PEHeader.ThreadLocalStorageTableDirectory) { } 14 | internal IEnumerable GetTlsCallbackPointers() 15 | { 16 | if (!IsValid) yield break; 17 | bool is32bit = Headers.PEHeader.Magic == PEMagic.PE32; 18 | 19 | // Read the TLS directory 20 | long cbAddress; 21 | if (is32bit) cbAddress = MemoryMarshal.Read(ImageData.Span.Slice(DirectoryOffset)).AddressOfCallBacks; 22 | else cbAddress = MemoryMarshal.Read(ImageData.Span.Slice(DirectoryOffset)).AddressOfCallBacks; 23 | 24 | if (cbAddress == 0) yield break; 25 | var callbackIndex = 0; 26 | while (true) 27 | { 28 | // Read the callback address 29 | var callbackAddressOffset = RelativeToOffset(VirtualToRelative(cbAddress)) + (is32bit? sizeof(int) : sizeof(long)) * callbackIndex; 30 | long callbackAddress = is32bit ? MemoryMarshal.Read(ImageData.Span.Slice(callbackAddressOffset)) : MemoryMarshal.Read(ImageData.Span.Slice(callbackAddressOffset)); 31 | if (callbackAddress == 0) yield break; 32 | yield return VirtualToRelative(callbackAddress); 33 | callbackIndex++; 34 | } 35 | } 36 | } 37 | 38 | [StructLayout(LayoutKind.Explicit, Size = 24)] 39 | public readonly struct PEImageTlsDirectory32 40 | { 41 | [FieldOffset(0xC)] 42 | public readonly int AddressOfCallBacks; 43 | } 44 | 45 | [StructLayout(LayoutKind.Explicit, Size = 40)] 46 | internal readonly struct PEImageTlsDirectory64 47 | { 48 | [FieldOffset(0x18)] 49 | public readonly long AddressOfCallBacks; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /T7CompilerLib/ScriptComponents/T7NameSection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.ScriptComponents 9 | { 10 | public sealed class T7NameSection : T7ScriptSection 11 | { 12 | const int SCRIPT_NAME_MAXSIZE = 256; 13 | private EndianType Endianess; 14 | private T7NameSection(bool littleEndian) { Endianess = littleEndian ? EndianType.LittleEndian : EndianType.BigEndian; } //Dont want initializers 15 | 16 | public static T7NameSection New(bool littleEndian) 17 | { 18 | return new T7NameSection(littleEndian); 19 | } 20 | 21 | /// 22 | /// The name of this script 23 | /// 24 | public string Value { get; set; } 25 | 26 | public override ushort Count() 27 | { 28 | return 1; 29 | } 30 | 31 | public override uint Size() 32 | { 33 | uint Base = GetBaseAddress(); 34 | return (ushort)(((uint)(Base + (Value.Length + 1))).AlignValue(0x10) - Base); 35 | } 36 | 37 | public static void ReadNameSection(ref byte[] raw, bool littleEndian, uint lpName, ref T7NameSection section) 38 | { 39 | section = new T7NameSection(littleEndian); 40 | 41 | if (raw.Length <= lpName) 42 | throw new ArgumentException("Couldn't parse the name pointer for this gsc because the pointer extends outside of the bounds of the input buffer."); 43 | 44 | EndianReader reader = new EndianReader(new MemoryStream(raw), section.Endianess); 45 | 46 | section.Value = reader.PeekNullTerminatedString(lpName, SCRIPT_NAME_MAXSIZE); 47 | 48 | reader.Dispose(); 49 | } 50 | 51 | public override byte[] Serialize() 52 | { 53 | byte[] bytes = new byte[Size()]; 54 | 55 | Encoding.ASCII.GetBytes(Value).CopyTo(bytes, 0); 56 | 57 | return bytes; 58 | } 59 | public override void UpdateHeader(ref T7ScriptHeader Header) 60 | { 61 | Header.NameOffset = GetBaseAddress(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /TreyarchCompiler/Games/BO3/BO3Syntax.cs: -------------------------------------------------------------------------------- 1 | using Irony.Parsing; 2 | 3 | namespace TreyarchCompiler.Games.BO3 4 | { 5 | [Language("Game Script", "T4.3", "GSC Grammar For Call of Duty Made By AgreedBog381, modified by S.")] 6 | internal sealed class BO3Syntax : BaseSyntax 7 | { 8 | #region Threadsafe 9 | //public new static Parser Parser => ThreadSafeInstance.SyntaxParser; 10 | private static readonly object InstanceLock = new object(); 11 | private static BO3Syntax instance; 12 | 13 | private static BO3Syntax ThreadSafeInstance 14 | { 15 | get 16 | { 17 | lock (InstanceLock) 18 | { 19 | return instance ?? (instance = new BO3Syntax()); 20 | } 21 | } 22 | } 23 | 24 | internal static ParseTree ParseCode(string code) 25 | { 26 | lock (InstanceLock) 27 | { 28 | return ThreadSafeInstance.SyntaxParser.Parse(code); 29 | } 30 | } 31 | #endregion 32 | 33 | #region Virtual 34 | private NonTerminal autoexec_priority => new NonTerminal("autoexec", ToTerm("autoexec", "autoexec_p") + "(" + NumberLiteral + ")" | ToTerm("autoexec", "autoexec_p")); 35 | protected override NonTerminal FunctionFrame => new NonTerminal("functionFrame", autoexec_priority + functions | functions | ToTerm("function") + autoexec_priority + functions | ToTerm("function") + functions); 36 | protected override NonTerminal NameSpaceDirective => new NonTerminal("namespace", "#namespace" + Identifier + ";"); 37 | protected override NonTerminal verbatimString => new NonTerminal("verbatimString", Unsupported); 38 | protected override NonTerminal iString => new NonTerminal("iString", ToTerm("&") + StringLiteral); 39 | protected override NonTerminal hashedString => new NonTerminal("hashedString", ToTerm("#") + StringLiteral); 40 | protected override NonTerminal canonHashed => new NonTerminal("canonHashed", ToTerm("#") + Identifier); 41 | //protected override NonTerminal usingTree => new NonTerminal("usingTree", ToTerm("#using_animtree") + "(" + StringLiteral + ")" + ";"); 42 | #endregion 43 | } 44 | } -------------------------------------------------------------------------------- /TreyarchCompiler/Games/BO2/BO2Syntax.cs: -------------------------------------------------------------------------------- 1 | using Irony.Parsing; 2 | 3 | namespace TreyarchCompiler.Games.BO2 4 | { 5 | [Language("Game Script", "T4.2", "GSC Grammar For Call of Duty Made By AgreedBog381, modified by S.")] 6 | internal sealed class BO2Syntax : BaseSyntax 7 | { 8 | #region Threadsafe 9 | //public new static Parser Parser => ThreadSafeInstance.SyntaxParser; 10 | private static readonly object InstanceLock = new object(); 11 | private static BO2Syntax instance; 12 | 13 | private static BO2Syntax ThreadSafeInstance 14 | { 15 | get 16 | { 17 | lock (InstanceLock) 18 | { 19 | return instance ?? (instance = new BO2Syntax()); 20 | } 21 | } 22 | } 23 | 24 | internal static ParseTree ParseCode(string code) 25 | { 26 | lock (InstanceLock) 27 | { 28 | return ThreadSafeInstance.SyntaxParser.Parse(code); 29 | } 30 | } 31 | #endregion 32 | 33 | #region Virtual 34 | protected override NonTerminal FunctionFrame => new NonTerminal("functionFrame", functions); 35 | protected override NonTerminal Overrides => new NonTerminal("overrides", ToTerm("#overrides") + IncludeIdentifier + ";"); 36 | protected override NonTerminal NameSpaceDirective => new NonTerminal("namespace", Unsupported); 37 | protected override NonTerminal verbatimString => new NonTerminal("verbatimString", Unsupported); 38 | protected override NonTerminal iString => new NonTerminal("iString", ToTerm("&") + StringLiteral); 39 | protected override NonTerminal hashedString => new NonTerminal("hashedString", Unsupported); 40 | protected override NonTerminal usingTree => new NonTerminal("usingTree", ToTerm("#using_animtree") + animTree + ";"); 41 | protected override NonTerminal animTree => new NonTerminal("animTree", ToTerm("%") + Identifier); 42 | protected override NonTerminal getAnimation => new NonTerminal("getAnimation", ToTerm("->") + Identifier); 43 | protected override NonTerminal animRef => new NonTerminal("animRef", animTree + getAnimation); 44 | #endregion 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_Jump.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace T89CompilerLib.OpCodes 4 | { 5 | public sealed class T89OP_Jump : T89OpCode 6 | { 7 | /// 8 | /// The opcode this jump should jump past 9 | /// 10 | public T89OpCode After; 11 | 12 | /// 13 | /// Should this jump use the loop head as a ref, or the loop end as a ref. 14 | /// 15 | public bool RefHead { get; internal set; } 16 | 17 | internal T89OP_Jump(ScriptOpCode code) 18 | { 19 | switch(code) 20 | { 21 | case ScriptOpCode.Jump: 22 | case ScriptOpCode.JumpOnFalse: 23 | case ScriptOpCode.JumpOnFalseExpr: 24 | case ScriptOpCode.JumpOnTrue: 25 | case ScriptOpCode.JumpOnTrueExpr: 26 | break; 27 | 28 | default: 29 | throw new ArgumentException("Cannot initialize a jump object with a non-jump related operation"); 30 | } 31 | Code = code; 32 | } 33 | 34 | protected override byte[] Serialize(ushort EmissionValue) 35 | { 36 | byte[] data = new byte[GetSize()]; 37 | 38 | base.Serialize(EmissionValue).CopyTo(data, 0); 39 | 40 | //This is just for identification of mis-written jumps in the output binary (if there are any) 41 | data[2] = 0xFF; 42 | data[3] = 0xFF; 43 | 44 | return data; 45 | } 46 | 47 | internal void CommitJump(ref byte[] data) 48 | { 49 | if (After == null) 50 | throw new NotImplementedException("A jump was recorded, but the opcode to jump to was never set..."); 51 | 52 | uint JumpTo = After.CommitAddress + After.GetSize(); 53 | uint JumpFrom = CommitAddress + GetSize(); 54 | 55 | BitConverter.GetBytes((short)(JumpTo - JumpFrom)).CopyTo(data, GetCommitDataAddress()); 56 | } 57 | 58 | public override uint GetCommitDataAddress() 59 | { 60 | return CommitAddress + T89OP_SIZE; 61 | } 62 | 63 | public override uint GetSize() 64 | { 65 | return T89OP_SIZE + 2; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /T8CompilerLib/ScriptComponents/T89GlobalObjectsSection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using T89CompilerLib.OpCodes; 8 | 9 | namespace T89CompilerLib.ScriptComponents 10 | { 11 | public class T89GlobalObjectsSection : T89ScriptSection 12 | { 13 | private Dictionary ObjectTable = new Dictionary(); 14 | public T89ScriptObject Script { get; private set; } 15 | private T89GlobalObjectsSection(T89ScriptObject script) 16 | { 17 | Script = script; 18 | } //Prevent public initializers 19 | 20 | internal static T89GlobalObjectsSection New(T89ScriptObject script) 21 | { 22 | return new T89GlobalObjectsSection(script); 23 | } 24 | 25 | public override ushort Count() 26 | { 27 | return (ushort)ObjectTable.Count; 28 | } 29 | 30 | public override byte[] Serialize() 31 | { 32 | byte[] data = new byte[Size()]; 33 | BinaryWriter writer = new BinaryWriter(new MemoryStream(data)); 34 | foreach(var entry in ObjectTable) 35 | { 36 | writer.Write(entry.Key); 37 | writer.Write(entry.Value.References.Count); 38 | foreach (var val in entry.Value.References) writer.Write(val.GetCommitDataAddress()); 39 | } 40 | writer.Close(); 41 | return data; 42 | } 43 | 44 | public override uint Size() 45 | { 46 | int count = 0; 47 | foreach (var entry in ObjectTable) count += 8 + (entry.Value.References.Count * 4); 48 | return (uint)count; 49 | } 50 | 51 | public override void UpdateHeader(ref T89ScriptHeader Header) 52 | { 53 | Header.GlobalObjectCount = Count(); 54 | Header.GlobalObjectTable = GetBaseAddress(); 55 | } 56 | 57 | public T89GlobalRef AddGlobal(uint value) 58 | { 59 | if (!ObjectTable.ContainsKey(value)) ObjectTable[value] = new T89GlobalRef(); 60 | return ObjectTable[value]; 61 | } 62 | } 63 | public class T89GlobalRef 64 | { 65 | internal HashSet References = new HashSet(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CComboDialog.cs: -------------------------------------------------------------------------------- 1 | using Refract.UI.Core.Interfaces; 2 | using Refract.UI.Core.Singletons; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel; 6 | using System.Data; 7 | using System.Drawing; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace SMC.UI.Core.Controls 14 | { 15 | public partial class CComboDialog : Form, IThemeableControl 16 | { 17 | public object SelectedValue { get; private set; } 18 | public int SelectedIndex { get; private set; } 19 | public CComboDialog(string title, object[] selectables, int defaultIndex = 0) 20 | { 21 | InitializeComponent(); 22 | UIThemeManager.OnThemeChanged(this, OnThemeChanged_Implementation); 23 | this.SetThemeAware(); 24 | MaximizeBox = true; 25 | MinimizeBox = true; 26 | Text = title; 27 | InnerForm.TitleBarTitle = title; 28 | cComboBox1.Items.Clear(); 29 | cComboBox1.Items.AddRange(selectables); 30 | if(defaultIndex > -1 && defaultIndex < selectables.Length) 31 | { 32 | cComboBox1.SelectedIndex = defaultIndex; 33 | } 34 | } 35 | 36 | private void OnThemeChanged_Implementation(UIThemeInfo themeData) 37 | { 38 | return; 39 | } 40 | 41 | public IEnumerable GetThemedControls() 42 | { 43 | yield return InnerForm; 44 | yield return cComboBox1; 45 | yield return AcceptButton; 46 | } 47 | 48 | private void AcceptButton_Click(object sender, EventArgs e) 49 | { 50 | DialogResult = DialogResult.OK; 51 | Close(); 52 | } 53 | 54 | private void cComboBox1_SelectedIndexChanged(object sender, EventArgs e) 55 | { 56 | SelectedIndex = cComboBox1.SelectedIndex; 57 | if(SelectedIndex >= 0 && SelectedIndex < cComboBox1.Items.Count) 58 | { 59 | SelectedValue = cComboBox1.Items[SelectedIndex]; 60 | } 61 | else 62 | { 63 | SelectedValue = null; 64 | } 65 | } 66 | 67 | private void InnerForm_Load(object sender, EventArgs e) 68 | { 69 | 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CTitleBar.cs: -------------------------------------------------------------------------------- 1 | using Refract.UI.Core.Interfaces; 2 | using Refract.UI.Core.Singletons; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel; 6 | using System.Data; 7 | using System.Drawing; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace Refract.UI.Core.Controls 14 | { 15 | public partial class CTitleBar : UserControl, IThemeableControl 16 | { 17 | public bool DisableDrag; 18 | public CTitleBar() 19 | { 20 | InitializeComponent(); 21 | MouseDown += MouseDown_Drag; 22 | UIThemeManager.RegisterCustomThemeHandler(typeof(CTitleBar), ApplyThemeCustomType_Implementation); 23 | UIThemeManager.OnThemeChanged(this, ApplyThemeCustom_Implementation); 24 | TitleLabel.MouseDown += MouseDown_Drag; 25 | } 26 | 27 | private void ExitButton_Click(object sender, EventArgs e) 28 | { 29 | ParentForm?.Close(); 30 | } 31 | 32 | public const int WM_NCLBUTTONDOWN = 0xA1; 33 | public const int HT_CAPTION = 0x2; 34 | 35 | [System.Runtime.InteropServices.DllImport("user32.dll")] 36 | public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); 37 | [System.Runtime.InteropServices.DllImport("user32.dll")] 38 | public static extern bool ReleaseCapture(); 39 | 40 | private void MouseDown_Drag(object sender, System.Windows.Forms.MouseEventArgs e) 41 | { 42 | if (ParentForm == null) return; 43 | if (DisableDrag) return; 44 | if (e.Button == MouseButtons.Left) 45 | { 46 | ReleaseCapture(); 47 | SendMessage(ParentForm.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); 48 | } 49 | } 50 | 51 | public void SetExitButtonVisible(bool isVisible) 52 | { 53 | ExitButton.Visible = isVisible; 54 | } 55 | 56 | private void ApplyThemeCustomType_Implementation(UIThemeInfo themeData) 57 | { 58 | 59 | } 60 | 61 | private void ApplyThemeCustom_Implementation(UIThemeInfo themeData) 62 | { 63 | ExitButton.BackColor = themeData.LightBackColor; 64 | } 65 | 66 | public IEnumerable GetThemedControls() 67 | { 68 | yield return ExitButton; 69 | yield return TitleLabel; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /T7CompilerLib/OpCodes/T7OP_Jump.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib.OpCodes 9 | { 10 | public sealed class T7OP_Jump : T7OpCode 11 | { 12 | /// 13 | /// The opcode this jump should jump past 14 | /// 15 | public T7OpCode After; 16 | 17 | public string TargetLabel = null; 18 | 19 | /// 20 | /// Should this jump use the loop head as a ref, or the loop end as a ref. 21 | /// 22 | public bool RefHead { get; internal set; } 23 | 24 | internal T7OP_Jump(ScriptOpCode code, EndianType endianess) : base(endianess) 25 | { 26 | switch(code) 27 | { 28 | case ScriptOpCode.Jump: 29 | case ScriptOpCode.JumpOnFalse: 30 | case ScriptOpCode.JumpOnFalseExpr: 31 | case ScriptOpCode.JumpOnTrue: 32 | case ScriptOpCode.JumpOnTrueExpr: 33 | break; 34 | 35 | default: 36 | throw new ArgumentException("Cannot initialize a jump object with a non-jump related operation"); 37 | } 38 | Code = code; 39 | } 40 | 41 | protected override byte[] Serialize(ushort EmissionValue) 42 | { 43 | byte[] data = new byte[GetSize()]; 44 | 45 | base.Serialize(EmissionValue).CopyTo(data, 0); 46 | 47 | //This is just for identification of mis-written jumps in the output binary (if there are any) 48 | data[data.Length - 2] = 0xFF; 49 | data[data.Length - 1] = 0xFF; 50 | 51 | return data; 52 | } 53 | 54 | internal void CommitJump(ref byte[] data) 55 | { 56 | if (After == null) 57 | throw new NotImplementedException("A jump was recorded, but the opcode to jump to was never set..."); 58 | 59 | uint JumpTo = After.CommitAddress + After.GetSize(); 60 | uint JumpFrom = CommitAddress + GetSize(); 61 | 62 | ((short)(JumpTo - JumpFrom)).GetBytes(Endianess).CopyTo(data, GetCommitDataAddress()); 63 | } 64 | 65 | public override uint GetCommitDataAddress() 66 | { 67 | return (CommitAddress + T7OP_SIZE).AlignValue(0x2); 68 | } 69 | 70 | public override uint GetSize() 71 | { 72 | return GetCommitDataAddress() + 2 - CommitAddress; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /External/PEStructures/PERelocationDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.PortableExecutable; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace System.PEStructures 11 | { 12 | public class PERelocationDirectory : PEDataDirectory 13 | { 14 | public PERelocationDirectory(PEHeaders headers, Memory imageData) : base(headers, imageData, headers.PEHeader.BaseRelocationTableDirectory) { } 15 | 16 | public IEnumerable<(int Offset, PERelocationType Type)> GetRelocations() 17 | { 18 | if (!IsValid) yield break; 19 | var lpCurrentRelocationBlock = DirectoryOffset; 20 | while (true) 21 | { 22 | // Read the relocation block 23 | var relocationBlock = MemoryMarshal.Read(ImageData.Span.Slice(lpCurrentRelocationBlock)); 24 | if (relocationBlock.SizeOfBlock == 0) break; 25 | var relocationCount = (relocationBlock.SizeOfBlock - Unsafe.SizeOf()) / sizeof(short); 26 | for (var relocationIndex = 0; relocationIndex < relocationCount; relocationIndex++) 27 | { 28 | // Read the relocation 29 | var relocationOffset = lpCurrentRelocationBlock + Unsafe.SizeOf() + sizeof(short) * relocationIndex; 30 | var relocation = MemoryMarshal.Read(ImageData.Span.Slice(relocationOffset)); 31 | 32 | // The type is located in the upper 4 bits of the relocation 33 | var type = (ushort)relocation >> 12; 34 | 35 | // The offset if located in the lower 12 bits of the relocation 36 | var offset = relocation & 0xFFF; 37 | yield return (RelativeToOffset(relocationBlock.VirtualAddress) + offset, (PERelocationType)type); 38 | } 39 | lpCurrentRelocationBlock += relocationBlock.SizeOfBlock; 40 | } 41 | } 42 | } 43 | public enum PERelocationType 44 | { 45 | RELOCATION_TYPE_HighLow = 0x3, 46 | RELOCATION_TYPE_Dir64 = 0xA 47 | } 48 | [StructLayout(LayoutKind.Explicit, Size = 8)] 49 | public readonly struct PEImageBaseRelocation 50 | { 51 | [FieldOffset(0x0)] 52 | public readonly int VirtualAddress; 53 | 54 | [FieldOffset(0x4)] 55 | public readonly int SizeOfBlock; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /External/Quartz/QAsm/QVariable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace System.Quartz.QAsm 9 | { 10 | public class QVariable 11 | { 12 | /// 13 | /// Type info for this variable 14 | /// 15 | public readonly QType TypeInfo; 16 | public bool IsConst; 17 | public object Value { get; private set; } 18 | 19 | private QVariable(QType typeinfo, bool isConst) 20 | { 21 | TypeInfo = typeinfo; 22 | IsConst = isConst; 23 | } 24 | 25 | public static QVariable AllocConst(string typename, QObj environment, string contextName, string rootContext) 26 | { 27 | var type = environment.LocateType(typename); 28 | var variable = new QVariable(type, true); 29 | QContextEntry context = new QContextEntry(variable, contextName, rootContext); 30 | environment.PutContext(context.FullContext, context); 31 | return variable; 32 | } 33 | 34 | public void SetValue(object value) 35 | { 36 | if(!IsConst) 37 | { 38 | throw new InvalidOperationException("Cannot set the value of a variable which is not constant."); 39 | } 40 | if(value is null) 41 | { 42 | throw new NullReferenceException("Tried to call SetValue with a null value"); 43 | } 44 | if(!TypeInfo.CanBox(value.GetType())) 45 | { 46 | throw new InvalidCastException($"Type mismatch for const declaration: {value.GetType()} is not a {TypeInfo.UnderlyingType}"); 47 | } 48 | Value = value; 49 | } 50 | } 51 | 52 | public class QType 53 | { 54 | public readonly string TypeName; 55 | public readonly Type UnderlyingType; 56 | public readonly bool IsReferenceType; 57 | private readonly int __sizeoverride; 58 | public int Size => IsReferenceType ? 8 : (__sizeoverride < 0 ? Marshal.SizeOf(UnderlyingType) : __sizeoverride); 59 | 60 | public bool CanBox(Type type) // compare type against our underlying type. If we can box it, return true. 61 | { 62 | return UnderlyingType == type; // TODO handle int to uint conversion, etc. 63 | } 64 | 65 | public QType(string typename, Type underlying, int sizeOverride = -1, bool isByReference = false) 66 | { 67 | UnderlyingType = underlying; 68 | TypeName = typename; 69 | __sizeoverride = sizeOverride; 70 | IsReferenceType = isByReference; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CThemedTextbox.cs: -------------------------------------------------------------------------------- 1 | using Refract.UI.Core.Interfaces; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.Linq; 8 | using System.Runtime.InteropServices; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace SMC.UI.Core.Controls 14 | { 15 | public partial class CThemedTextbox : TextBox 16 | { 17 | const int WM_NCPAINT = 0x85; 18 | const uint RDW_INVALIDATE = 0x1; 19 | const uint RDW_IUPDATENOW = 0x100; 20 | const uint RDW_FRAME = 0x400; 21 | [DllImport("user32.dll")] 22 | static extern IntPtr GetWindowDC(IntPtr hWnd); 23 | [DllImport("user32.dll")] 24 | static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); 25 | [DllImport("user32.dll")] 26 | static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprc, IntPtr hrgn, uint flags); 27 | 28 | private Color __borderColor = Color.Red; 29 | public Color BorderColor 30 | { 31 | get { return __borderColor; } 32 | set 33 | { 34 | __borderColor = value; 35 | RedrawWindow(Handle, IntPtr.Zero, IntPtr.Zero, 36 | RDW_FRAME | RDW_IUPDATENOW | RDW_INVALIDATE); 37 | } 38 | } 39 | protected override void WndProc(ref Message m) 40 | { 41 | 42 | if (m.Msg == WM_NCPAINT && BorderColor != Color.Transparent && 43 | BorderStyle == BorderStyle.Fixed3D) 44 | { 45 | var hdc = GetWindowDC(this.Handle); 46 | using (var g = Graphics.FromHdcInternal(hdc)) 47 | { 48 | using (var p = new Pen(BorderColor)) 49 | { 50 | g.DrawRectangle(p, new Rectangle(0, 0, Width - 1, Height - 1)); 51 | } 52 | 53 | using (var p = new Pen(BackColor)) 54 | { 55 | g.DrawRectangle(p, new Rectangle(1, 1, Width - 3, Height - 3)); 56 | } 57 | } 58 | 59 | ReleaseDC(this.Handle, hdc); 60 | } 61 | else 62 | { 63 | base.WndProc(ref m); 64 | } 65 | } 66 | protected override void OnSizeChanged(EventArgs e) 67 | { 68 | base.OnSizeChanged(e); 69 | RedrawWindow(Handle, IntPtr.Zero, IntPtr.Zero, 70 | RDW_FRAME | RDW_IUPDATENOW | RDW_INVALIDATE); 71 | } 72 | 73 | public CThemedTextbox() 74 | { 75 | InitializeComponent(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /t7cinternal/Opcodes.cpp: -------------------------------------------------------------------------------- 1 | #include "Opcodes.h" 2 | #include "offsets.h" 3 | #include "detours.h" 4 | #include "builtins.h" 5 | 6 | void Opcodes::Init() 7 | { 8 | // note: on windows store these are RDATA!! 9 | 10 | // Change Opcode Handler 0x16 to VM_OP_GetLazyFunction 11 | chgmem(0x16 * 8 + OFF_ScrVm_Opcodes, (uint64_t)VM_OP_GetLazyFunction); 12 | 13 | // Change Opcode Handler 0x17 to VM_OP_GetLocalFunction 14 | chgmem(0x17 * 8 + OFF_ScrVm_Opcodes, (uint64_t)VM_OP_GetLocalFunction); 15 | 16 | // Change Opcode Handler 0x1A to VM_OP_NOP 17 | chgmem(0x1A * 8 + OFF_ScrVm_Opcodes, (uint64_t)VM_OP_NOP); 18 | } 19 | 20 | void Opcodes::VM_OP_GetLazyFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate) 21 | { 22 | INT64 base = (*fs_0 + 3) & 0xFFFFFFFFFFFFFFFCLL; 23 | INT32 Namespace = *(INT32*)base; 24 | INT32 Function = *(INT32*)(base + 4); 25 | char* script = (char*)(*fs_0 + (*(INT32*)(base + 8))); 26 | auto asset = ScriptDetours::FindScriptParsetree(script); 27 | 28 | if (!asset) 29 | { 30 | *(INT32*)(fs_0[1] + 0x18) = 0x0; // undefined 31 | fs_0[1] += 0x10; // change stack top 32 | *fs_0 = base + 0xC; // move past the data 33 | return; 34 | } 35 | 36 | auto buffer = *(char**)(asset + 0x10); 37 | auto exportsOffset = *(INT32*)(buffer + 0x20); 38 | auto exports = (INT64)(exportsOffset + buffer); 39 | auto numExports = *(INT16*)(buffer + 0x3A); 40 | __t7export* currentExport = (__t7export*)exports; 41 | bool found = false; 42 | 43 | for (INT16 i = 0; i < numExports; i++, currentExport++) 44 | { 45 | if (currentExport->funcName != Function) 46 | { 47 | continue; 48 | } 49 | if (currentExport->funcNS != Namespace) 50 | { 51 | continue; 52 | } 53 | found = true; 54 | break; 55 | } 56 | 57 | if (!found) 58 | { 59 | *(INT32*)(fs_0[1] + 0x18) = 0x0; // undefined 60 | fs_0[1] += 0x10; // change stack top 61 | *fs_0 = base + 0xC; // move past the data 62 | return; 63 | } 64 | 65 | *(INT32*)(fs_0[1] + 0x18) = 0xE; // assign the top variable's type 66 | *(INT64*)(fs_0[1] + 0x10) = (INT64)buffer + currentExport->bytecodeOffset; // assign the top variable's value 67 | fs_0[1] += 0x10; // change stack top 68 | *fs_0 = base + 0xC; // move past the data 69 | } 70 | 71 | void Opcodes::VM_OP_GetLocalFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate) 72 | { 73 | INT64 base = (*fs_0 + 3) & 0xFFFFFFFFFFFFFFFCLL; 74 | INT32 jumpOffset = *(INT32*)base; 75 | *fs_0 = base + 0x4; // move past the data 76 | 77 | INT64 fnPtr = *fs_0 + jumpOffset; 78 | *(INT32*)(fs_0[1] + 0x18) = 0xE; // assign the top variable's type 79 | *(INT64*)(fs_0[1] + 0x10) = (INT64)fnPtr; // assign the top variable's value 80 | fs_0[1] += 0x10; // change stack top 81 | } 82 | 83 | void Opcodes::VM_OP_NOP(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate) 84 | { 85 | } 86 | -------------------------------------------------------------------------------- /External/ExThreads/ThreadContextEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | //https://github.com/CCob/SharpBlock/blob/c7f6fcb9ca9ffa80fe8862b165196098d9afbe20/Context.cs#L32 9 | namespace System.ExThreads 10 | { 11 | public enum ThreadContextExFlags 12 | { 13 | All, 14 | Debug 15 | } 16 | 17 | public enum ThreadAccess : int 18 | { 19 | TERMINATE = (0x0001), 20 | SUSPEND_RESUME = (0x0002), 21 | GET_CONTEXT = (0x0008), 22 | SET_CONTEXT = (0x0010), 23 | SET_INFORMATION = (0x0020), 24 | QUERY_INFORMATION = (0x0040), 25 | SET_THREAD_TOKEN = (0x0080), 26 | IMPERSONATE = (0x0100), 27 | DIRECT_IMPERSONATION = (0x0200), 28 | THREAD_HIJACK = SUSPEND_RESUME | GET_CONTEXT | SET_CONTEXT, 29 | THREAD_ALL = TERMINATE | SUSPEND_RESUME | GET_CONTEXT | SET_CONTEXT | SET_INFORMATION | QUERY_INFORMATION | SET_THREAD_TOKEN | IMPERSONATE | DIRECT_IMPERSONATION 30 | } 31 | 32 | public abstract class ThreadContextEx : IDisposable 33 | { 34 | 35 | private PointerEx hInternalMemory; 36 | private PointerEx hAlignedMemory; 37 | 38 | public ThreadContextEx() 39 | { 40 | //Get/SetThreadContext needs to be 16 byte aligned memory offset on x64 41 | hInternalMemory = Marshal.AllocHGlobal(Marshal.SizeOf(ContextStruct) + 1024); 42 | hAlignedMemory = (long)hInternalMemory & ~0xF; 43 | } 44 | 45 | public void Dispose() 46 | { 47 | if (hInternalMemory) 48 | { 49 | Marshal.FreeHGlobal(hInternalMemory); 50 | } 51 | } 52 | 53 | public bool GetContext(PointerEx thread) 54 | { 55 | Marshal.StructureToPtr(ContextStruct, hAlignedMemory, false); 56 | bool result = GetContext(thread, hAlignedMemory); 57 | ContextStruct = Marshal.PtrToStructure(hAlignedMemory, ContextStruct.GetType()); 58 | return result; 59 | } 60 | 61 | public bool SetContext(PointerEx thread) 62 | { 63 | Marshal.StructureToPtr(ContextStruct, hAlignedMemory, false); 64 | return SetContext(thread, hAlignedMemory); 65 | } 66 | 67 | public ulong SetBits(ulong dw, int lowBit, int bits, ulong newValue) 68 | { 69 | ulong mask = (1UL << bits) - 1UL; 70 | dw = (dw & ~(mask << lowBit)) | (newValue << lowBit); 71 | return dw; 72 | } 73 | 74 | protected abstract object ContextStruct { get; set; } 75 | 76 | protected abstract bool SetContext(PointerEx thread, PointerEx context); 77 | 78 | protected abstract bool GetContext(PointerEx thread, PointerEx context); 79 | 80 | public abstract PointerEx InstructionPointer { get; set; } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /TreyarchCompiler/Games/BLOPSCompiler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using Irony.Parsing; 5 | using TreyarchCompiler.Enums; 6 | using TreyarchCompiler.Utilities; 7 | 8 | namespace TreyarchCompiler.Games 9 | { 10 | internal abstract class BLOPSCompilerBase 11 | { 12 | protected struct Helpers 13 | { 14 | internal static readonly string UndefinedCall = "0undefinedFunction"; 15 | 16 | //internal variables 17 | internal static readonly string BooleanExpression = "0booleanExpression"; 18 | internal static readonly string BogsArrayKeys = "0bogsArrayKeys"; 19 | internal static readonly string BogsArrayIndex = "0bogsIndex"; 20 | 21 | //Preprocessor Global Variables 22 | internal static readonly string PreProcessGlobal = "0preProcessGlobal_"; 23 | } 24 | 25 | //------------- Syntax & Parser -------------\\ 26 | protected ParseTree _tree; 27 | 28 | //------------- Bytecode & Buffer -------------\\ 29 | protected readonly List _byteCode; 30 | protected readonly List _buffer; 31 | 32 | //------------- Foreach Statement Support -------------\\ 33 | protected readonly Random _random; 34 | protected readonly List _forEachKeys; //for interop, not removed, but deprecated due to async 35 | 36 | //------------- Optional Parameters Support -------------\\ 37 | protected readonly List _localParameterNodes; 38 | 39 | //THIS WILL HOLD THE BEGIN POSITIONS OF ALL DEFINITIONS FOR JUMPS 40 | //HOLDS ALL CALL POSITIONS WITH CALL NAME && DEC NAME 41 | protected readonly Dictionary _functionDefIndex; 42 | protected string _currentDeclaration;//Used to help with debug info 43 | 44 | //------------- Local Variables -------------\\ 45 | protected readonly List _localVariables; 46 | 47 | //------------- Dubug Support -------------\\ 48 | protected readonly List _warnings; 49 | protected readonly List _undefinedVariables; 50 | protected string _path; 51 | protected Modes _mode; 52 | 53 | protected BLOPSCompilerBase() 54 | { 55 | _byteCode = new List(); 56 | _buffer = new List(); 57 | 58 | _random = new Random(); 59 | _functionDefIndex = new Dictionary(); 60 | 61 | _warnings = new List(); 62 | _undefinedVariables = new List(); 63 | } 64 | 65 | protected void WriteFile(string location, string fileName, byte[] data) 66 | { 67 | var stream = new FileStream(Path.Combine(location, fileName), FileMode.Create); 68 | stream.Write(data, 0, data.Length); 69 | stream.Close(); 70 | stream.Dispose(); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /ExternalTestingUtility/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace t7c_installer.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("t7mpforcehost.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /t8cinternal/detours.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | #include 4 | #include 5 | 6 | struct ScriptDetour 7 | { 8 | INT64 ReplaceScriptName; 9 | INT32 ReplaceNamespace; 10 | INT32 ReplaceFunction; 11 | INT64 hFixup; 12 | INT32 FixupSize; 13 | }; 14 | 15 | struct __t8export 16 | { 17 | INT32 discardCRC32; 18 | INT32 bytecodeOffset; 19 | INT32 funcName; 20 | INT32 funcNS; 21 | INT32 funcNS_discard; 22 | INT32 discardParamsFlagsPad; 23 | }; 24 | 25 | struct SPTEntry 26 | { 27 | INT64 Name; 28 | INT64 pad; 29 | char* Buffer; 30 | INT32 size; 31 | INT32 Unk0; 32 | }; 33 | 34 | typedef void(__fastcall* tVM_Opcode)(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 35 | typedef INT64(__fastcall* tScr_GetFunction)(INT32 canonID, INT32* type, INT32* min_args, INT32* max_args); 36 | typedef INT64(__fastcall* tScr_GetMethod)(INT32 canonID, INT32* type, INT32* min_args, INT32* max_args); 37 | typedef INT64(__fastcall* tDB_FindXAssetHeader)(int type, char* name, bool errorIfMissing, int waitTime); 38 | typedef INT64(__fastcall* tScr_GscObjLink)(int inst, char* gsc_obj); 39 | 40 | #define DETOUR_LOGGING 41 | 42 | class ScriptDetours 43 | { 44 | public: 45 | static std::vector RegisteredDetours; 46 | static std::unordered_map LinkedDetours; 47 | static std::unordered_map AppliedFixups; 48 | static INT64 FindScriptParsetree(INT64 name); 49 | static bool DetoursLinked; 50 | static bool DetoursReset; 51 | static bool DetoursEnabled; 52 | static bool DetoursInitialized; 53 | static char* GSC_OBJ; 54 | static void InstallHooks(); 55 | static void LinkDetours(); 56 | 57 | private: 58 | static void VTableReplace(INT32 sub_offset, tVM_Opcode ReplaceFunc, tVM_Opcode* OutOld); 59 | static void VM_OP_GetFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 60 | static void VM_OP_GetAPIFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 61 | static void VM_OP_ScriptFunctionCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 62 | static void VM_OP_ScriptMethodCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 63 | static void VM_OP_ScriptThreadCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 64 | static void VM_OP_ScriptMethodThreadCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 65 | static void VM_OP_CallBuiltin(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 66 | static void VM_OP_CallBuiltinMethod(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 67 | static bool CheckDetour(INT32 inst, INT64* fs_0, INT32 offset = 0); 68 | static tScr_GetFunction Scr_GetFunction; 69 | static tScr_GetMethod Scr_GetMethod; 70 | static tScr_GscObjLink Scr_GscObjLink; 71 | static tDB_FindXAssetHeader DB_FindXAssetHeader; 72 | static tVM_Opcode VM_OP_GetFunction_Old; 73 | static tVM_Opcode VM_OP_GetAPIFunction_Old; 74 | static tVM_Opcode VM_OP_ScriptFunctionCall_Old; 75 | static tVM_Opcode VM_OP_ScriptMethodCall_Old; 76 | static tVM_Opcode VM_OP_ScriptThreadCall_Old; 77 | static tVM_Opcode VM_OP_ScriptMethodThreadCall_Old; 78 | static tVM_Opcode VM_OP_CallBuiltin_Old; 79 | static tVM_Opcode VM_OP_CallBuiltinMethod_Old; 80 | }; -------------------------------------------------------------------------------- /T7CompilerLib/ScriptComponents/T7StringFixupsSection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace T7CompilerLib.ScriptComponents 5 | { 6 | public sealed class T7StringFixupsSection : T7ScriptSection 7 | { 8 | private T7StringTableSection StringTable; 9 | private int SIZEOF_FIXUP 10 | { 11 | get 12 | { 13 | if (StringTable.Endianess == EndianType.LittleEndian) 14 | return 8; 15 | 16 | return 4; 17 | } 18 | } 19 | 20 | private T7StringFixupsSection() { } 21 | public static T7StringFixupsSection New(T7StringTableSection strings) 22 | { 23 | T7StringFixupsSection fixups = new T7StringFixupsSection(); 24 | fixups.StringTable = strings; 25 | return fixups; 26 | } 27 | 28 | public override ushort Count() 29 | { 30 | int count = 0; 31 | foreach(var KvP in StringTable.TableEntries) 32 | { 33 | count += KvP.Value.NumEntryEmissions(); 34 | } 35 | return (ushort)count; 36 | } 37 | 38 | public override byte[] Serialize() 39 | { 40 | byte[] data = new byte[Size()]; 41 | 42 | EndianWriter writer = new EndianWriter(data, StringTable.Endianess); 43 | 44 | foreach (var KvP in StringTable.TableEntries) 45 | { 46 | int index = 0; 47 | uint[] strrefs = KvP.Value.CollectReferences(); 48 | 49 | while (index < strrefs.Length) 50 | { 51 | if(index % 250 == 0) 52 | { 53 | if (StringTable.Endianess == EndianType.LittleEndian) 54 | writer.Write(KvP.Value.EmissionLocation); 55 | else 56 | writer.Write((ushort)KvP.Value.EmissionLocation); 57 | 58 | writer.Write((byte)Math.Min(strrefs.Length - index, 250)); 59 | writer.Write((byte)0); 60 | 61 | if (StringTable.Endianess == EndianType.LittleEndian) 62 | writer.Write((ushort)0); 63 | } 64 | writer.Write(strrefs[index++]); 65 | } 66 | } 67 | writer.Dispose(); 68 | 69 | return data; 70 | } 71 | 72 | public override uint Size() 73 | { 74 | uint count = 0; 75 | foreach (var KvP in StringTable.TableEntries) 76 | { 77 | count += (uint)((KvP.Value.NumEntryEmissions() * SIZEOF_FIXUP) + (KvP.Value.CollectReferences().Length * sizeof(int))); 78 | } 79 | 80 | count = count.AlignValue(0x10); //meet section alignment requirements 81 | return count; 82 | } 83 | 84 | public override void UpdateHeader(ref T7ScriptHeader Header) 85 | { 86 | Header.StringCount = Count(); 87 | Header.StringTableOffset = GetBaseAddress(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /t7cinternal/detours.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | #include 4 | #include 5 | 6 | struct ScriptDetour 7 | { 8 | char ReplaceScriptName[256]; 9 | INT32 ReplaceNamespace; 10 | INT32 ReplaceFunction; 11 | INT64 hFixup; 12 | INT32 FixupSize; 13 | }; 14 | 15 | struct __t7export 16 | { 17 | INT32 discardCRC32; 18 | INT32 bytecodeOffset; 19 | INT32 funcName; 20 | INT32 funcNS; 21 | INT32 discardParamsFlagsPad; 22 | }; 23 | 24 | struct SPTEntry 25 | { 26 | char* Name; 27 | INT32 buffSize; 28 | INT32 flags; 29 | char* Buffer; 30 | }; 31 | 32 | typedef void(__fastcall* tVM_Opcode)(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 33 | typedef INT64(__fastcall* tScr_GetFunction)(INT32 canonID, INT32* type, INT32* min_args, INT32* max_args); 34 | typedef INT64(__fastcall* tScr_GetMethod)(INT32 canonID, INT32* type, INT32* min_args, INT32* max_args); 35 | typedef INT64(__fastcall* tDB_FindXAssetHeader)(int type, char* name, bool errorIfMissing, int waitTime); 36 | typedef INT64(__fastcall* tScr_GscObjLink)(int inst, char* gsc_obj); 37 | 38 | //#define DETOUR_LOGGING 39 | 40 | EXPORT bool RegisterDetours(void* DetourData, int NumDetours, INT64 scriptOffset); 41 | 42 | class ScriptDetours 43 | { 44 | public: 45 | static std::vector RegisteredDetours; 46 | static std::unordered_map LinkedDetours; 47 | static std::unordered_map AppliedFixups; 48 | static INT64 FindScriptParsetree(char* name); 49 | static bool DetoursLinked; 50 | static bool DetoursReset; 51 | static bool DetoursEnabled; 52 | static char* GSC_OBJ; 53 | static void InstallHooks(); 54 | static void LinkDetours(); 55 | static void ResetDetours(); 56 | static void RegisterRuntimeDetour(INT64 hFixup, INT32 replaceFunc, INT32 replaceNS, const char* replaceScriptName, char* fPosOrNull); 57 | 58 | private: 59 | static void VTableReplace(INT64 stub_final, tVM_Opcode ReplaceFunc, tVM_Opcode* OutOld); 60 | static void VM_OP_GetFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 61 | static void VM_OP_GetAPIFunction(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 62 | static void VM_OP_ScriptFunctionCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 63 | static void VM_OP_ScriptMethodCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 64 | static void VM_OP_ScriptThreadCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 65 | static void VM_OP_ScriptMethodThreadCall(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 66 | static void VM_OP_CallBuiltin(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 67 | static void VM_OP_CallBuiltinMethod(INT32 inst, INT64* fs_0, INT64 vmc, bool* terminate); 68 | static bool CheckDetour(INT32 inst, INT64* fs_0, INT32 offset = 0); 69 | static tScr_GetFunction Scr_GetFunction; 70 | static tScr_GetMethod Scr_GetMethod; 71 | static tScr_GscObjLink Scr_GscObjLink; 72 | static tDB_FindXAssetHeader DB_FindXAssetHeader; 73 | static tVM_Opcode VM_OP_GetFunction_Old; 74 | static tVM_Opcode VM_OP_GetAPIFunction_Old; 75 | static tVM_Opcode VM_OP_ScriptFunctionCall_Old; 76 | static tVM_Opcode VM_OP_ScriptMethodCall_Old; 77 | static tVM_Opcode VM_OP_ScriptThreadCall_Old; 78 | static tVM_Opcode VM_OP_ScriptMethodThreadCall_Old; 79 | static tVM_Opcode VM_OP_CallBuiltin_Old; 80 | static tVM_Opcode VM_OP_CallBuiltinMethod_Old; 81 | }; -------------------------------------------------------------------------------- /T8CompilerLib/Utility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace T89CompilerLib 6 | { 7 | /// 8 | /// Utility Functions 9 | /// 10 | internal static class Utility 11 | { 12 | /// 13 | /// Computes the number of bytes require to pad this value 14 | /// 15 | public static int ComputePadding(int value, int alignment) => (((value) + ((alignment) - 1)) & ~((alignment) - 1)) - value; 16 | 17 | /// 18 | /// Aligns the value to the given alignment 19 | /// 20 | public static int AlignValue(this int value, int alignment) => (((value) + ((alignment) - 1)) & ~((alignment) - 1)); 21 | 22 | public static uint AlignValue(this uint value, uint alignment) => (((value) + ((alignment) - 1)) & ~((alignment) - 1)); 23 | 24 | /// 25 | /// Determines if a context value meets a desired value 26 | /// 27 | /// 28 | /// 29 | /// 30 | public static bool HasContext(this uint context, ScriptContext desired) 31 | { 32 | return (context & (uint)desired) > 0; 33 | } 34 | 35 | /// 36 | /// Reads a string terminated by a null byte and returns the reader to the original position 37 | /// 38 | /// Read String 39 | public static string PeekNullTerminatedString(this BinaryReader br, long offset, int maxSize = -1) 40 | { 41 | // Create String Builder 42 | StringBuilder str = new StringBuilder(); 43 | // Seek to position 44 | var temp = br.BaseStream.Position; 45 | br.BaseStream.Position = offset; 46 | // Current Byte Read 47 | int byteRead; 48 | // Size of String 49 | int size = 0; 50 | // Loop Until we hit terminating null character 51 | while ((byteRead = br.BaseStream.ReadByte()) != 0x0 && size++ != maxSize) 52 | str.Append(Convert.ToChar(byteRead)); 53 | // Go back 54 | br.BaseStream.Position = temp; 55 | // Ship back Result 56 | return str.ToString(); 57 | } 58 | 59 | /// 60 | /// Writes a null terminated string 61 | /// 62 | /// 63 | /// 64 | public static void WriteNullTerminatedString(this BinaryWriter br, string str) 65 | { 66 | foreach (byte c in Encoding.ASCII.GetBytes(str)) 67 | br.Write(c); 68 | br.Write((byte)0); 69 | } 70 | 71 | /// 72 | /// Counts the number of lines in the given string 73 | /// 74 | public static int GetLineCount(string str) 75 | { 76 | int index = -1; 77 | int count = 0; 78 | while ((index = str.IndexOf(Environment.NewLine, index + 1)) != -1) 79 | count++; 80 | return count + 1; 81 | } 82 | 83 | public static string SanitiseString(string value) => value.Replace("/", "\\").Replace("\b", "\\b"); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /TreyarchCompiler/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TreyarchCompiler.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TreyarchCompiler.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to . 65 | /// 66 | internal static string String { 67 | get { 68 | return ResourceManager.GetString("String", resourceCulture); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ExternalTestingUtility/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 59 | 60 | 61 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /External/Quartz/QAsm/QObj.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace System.Quartz.QAsm 9 | { 10 | public class QObj 11 | { 12 | private HashSet ReadOnlyData; 13 | private HashSet ExternCache; 14 | 15 | private Dictionary ContextualEntries; 16 | private QContextEntry RootContext; 17 | private Dictionary EnvTypes; 18 | 19 | public QObj() 20 | { 21 | ContextualEntries = new Dictionary(); 22 | ReadOnlyData = new HashSet(); 23 | ExternCache = new HashSet(); 24 | EnvTypes = new Dictionary(); 25 | RegisterBuiltinTypes(); 26 | } 27 | 28 | private void RegisterBuiltinTypes() 29 | { 30 | EnvTypes["qword"] = new QType("qword", typeof(ulong)); 31 | EnvTypes["dword"] = new QType("dword", typeof(uint)); 32 | EnvTypes["word"] = new QType("word", typeof(ushort)); 33 | EnvTypes["byte"] = new QType("byte", typeof(byte)); 34 | EnvTypes["bool"] = new QType("bool", typeof(bool)); 35 | EnvTypes["string"] = new QType("string", typeof(string), -1, true); 36 | } 37 | 38 | public QType LocateType(string typename) 39 | { 40 | if(EnvTypes.TryGetValue(typename, out QType value)) 41 | { 42 | return value; 43 | } 44 | throw new KeyNotFoundException($"Unknown type '{typename}'"); 45 | } 46 | 47 | /// 48 | /// Register a context entry, later used for lookups 49 | /// 50 | /// 51 | /// 52 | public void PutContext(string fullContext, QContextEntry entry) 53 | { 54 | if(fullContext is null) 55 | { 56 | if(RootContext != null) 57 | { 58 | throw new InvalidOperationException("Cannot put a root context when a root context already exists"); 59 | } 60 | RootContext = entry; 61 | return; 62 | } 63 | if(ContextualEntries.ContainsKey(fullContext)) 64 | { 65 | throw new DuplicateNameException($"Name '{fullContext}' already exists."); 66 | } 67 | ContextualEntries[fullContext] = entry; 68 | } 69 | 70 | public void PutReadonly(QVariable variable) 71 | { 72 | ReadOnlyData.Add(variable); 73 | } 74 | 75 | public void PutExtern(QVariable variable) 76 | { 77 | ExternCache.Add(variable); 78 | } 79 | } 80 | 81 | public class QContextEntry 82 | { 83 | public const string CONTEXT_ANONYMOUS = "anon_0"; 84 | public readonly string Name; 85 | public readonly string ParentContext; 86 | public string FullContext => ParentContext is null ? Name : $"{ParentContext}.{Name}"; 87 | public object Value { private set; get; } 88 | 89 | public QContextEntry(object value, string context, string parentContext) 90 | { 91 | Value = value; 92 | ParentContext = parentContext; 93 | Name = context; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Application/MainForm.cs: -------------------------------------------------------------------------------- 1 | using Refract.UI.Core.Interfaces; 2 | using Refract.UI.Core.Singletons; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel; 6 | using System.Data; 7 | using System.Drawing; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | using System.Diagnostics; 13 | using SMC.UI.Core.Controls; 14 | 15 | namespace t7c_installer 16 | { 17 | public partial class MainForm : Form, IThemeableControl 18 | { 19 | public MainForm() 20 | { 21 | InitializeComponent(); 22 | UIThemeManager.OnThemeChanged(this, OnThemeChanged_Implementation); 23 | this.SetThemeAware(); 24 | MaximizeBox = true; 25 | MinimizeBox = true; 26 | } 27 | 28 | public IEnumerable GetThemedControls() 29 | { 30 | yield return InnerForm; 31 | yield return UpdateButton; 32 | yield return ConvertProj; 33 | yield return InstallVSCExt; 34 | yield return JoinDiscord; 35 | yield return CreateDefaultProject; 36 | } 37 | 38 | private void OnThemeChanged_Implementation(UIThemeInfo currentTheme) 39 | { 40 | } 41 | 42 | private void RPCTest1_Click(object sender, EventArgs e) 43 | { 44 | 45 | } 46 | 47 | private void RPCExample2_Click(object sender, EventArgs e) 48 | { 49 | 50 | } 51 | 52 | private void RPCExample3_Click(object sender, EventArgs e) 53 | { 54 | } 55 | 56 | private void ExampleRPC4_Click(object sender, EventArgs e) 57 | { 58 | } 59 | 60 | private void button1_Click(object sender, EventArgs e) 61 | { 62 | } 63 | 64 | private void JoinDiscord_Click(object sender, EventArgs e) 65 | { 66 | Process.Start("https://gsc.dev/s/discord"); 67 | } 68 | 69 | private void UpdateButton_Click(object sender, EventArgs e) 70 | { 71 | Program.InstallUpdate(); 72 | CErrorDialog.Show("Success!", "Compiler installed successfully", true); 73 | } 74 | 75 | private void InstallVSCExt_Click(object sender, EventArgs e) 76 | { 77 | Program.UpdateVSCExtension(); 78 | CErrorDialog.Show("Success!", "Extension installed successfully", true); 79 | } 80 | 81 | private void CreateDefaultProject_Click(object sender, EventArgs e) 82 | { 83 | var box = new CComboDialog("Game for Project", new string[] { "Black Ops III", "Black Ops 4" }); 84 | if (box.ShowDialog() != DialogResult.OK) 85 | { 86 | return; 87 | } 88 | var game = (box.SelectedValue.ToString() == "Black Ops 4") ? "T8" : "T7"; 89 | FolderBrowserDialog fbd = new FolderBrowserDialog(); 90 | fbd.ShowNewFolderButton = true; 91 | fbd.Description = "Select a folder to copy the default project to"; 92 | if (fbd.ShowDialog() != DialogResult.OK) return; 93 | Program.CopyDefaultProject(fbd.SelectedPath, game); 94 | Process.Start(fbd.SelectedPath); 95 | CErrorDialog.Show("Success!", "Project installed successfully", true); 96 | } 97 | 98 | private void ConvertProj_Click(object sender, EventArgs e) 99 | { 100 | Visible = false; 101 | new ImportDialog().ShowDialog(); 102 | Visible = true; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /T8CompilerLib/ScriptComponents/T89IncludesSection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using System.IO; 5 | 6 | namespace T89CompilerLib.ScriptComponents 7 | { 8 | public sealed class T89IncludesSection : T89ScriptSection 9 | { 10 | /// 11 | /// Internal list of includes 12 | /// 13 | public HashSet Includes = new HashSet(); 14 | 15 | public T89ScriptObject Script { get; private set; } 16 | private T89IncludesSection(T89ScriptObject script) { Script = script; } //We dont want initializations of this class without our deserialization procedures 17 | 18 | public static T89IncludesSection New(T89ScriptObject script) 19 | { 20 | T89IncludesSection section = new T89IncludesSection(script); 21 | section.Includes = new HashSet(); 22 | return section; 23 | } 24 | 25 | /// 26 | /// Add an include to this script 27 | /// 28 | /// 29 | public void Add(ulong Include) 30 | { 31 | Includes.Add(Include); 32 | } 33 | 34 | /// 35 | /// Remove an include from this script 36 | /// 37 | /// 38 | public void Remove(ulong Include) 39 | { 40 | Includes.Remove(Include); 41 | } 42 | 43 | /// 44 | /// Number of includes in this section 45 | /// 46 | /// 47 | public override ushort Count() 48 | { 49 | return (ushort)Includes.Count; 50 | } 51 | 52 | /// 53 | /// Returns the section size. For includes, this consists of the string and the reference for each include. 54 | /// 55 | /// 56 | public override uint Size() 57 | { 58 | uint count = 0; 59 | 60 | foreach (ulong s in Includes) 61 | count += 8; 62 | 63 | uint Base = GetBaseAddress(); 64 | 65 | count = (Base + count).AlignValue(0x10) - Base; 66 | 67 | return count; 68 | } 69 | 70 | public static void ReadIncludes(ref byte[] data, uint IncludesPosition, ushort NumIncludes, ref T89IncludesSection section, T89ScriptObject script) 71 | { 72 | T89IncludesSection includes = new T89IncludesSection(script); 73 | section = includes; 74 | 75 | if (NumIncludes < 1) 76 | return; 77 | 78 | if (data.Length <= IncludesPosition) 79 | throw new ArgumentException("GSC could not be parsed because the includes pointer was outside of boundaries of the input buffer."); 80 | 81 | BinaryReader reader = new BinaryReader(new MemoryStream(data)); 82 | reader.BaseStream.Position = IncludesPosition; 83 | 84 | for(byte i = 0; i < NumIncludes; i++) 85 | { 86 | includes.Includes.Add(reader.ReadUInt64()); 87 | } 88 | 89 | reader.Dispose(); 90 | } 91 | 92 | public override byte[] Serialize() 93 | { 94 | byte[] data = new byte[Size()]; 95 | 96 | BinaryWriter writer = new BinaryWriter(new MemoryStream(data)); 97 | 98 | foreach(ulong s in Includes) 99 | writer.Write(s); 100 | 101 | writer.Dispose(); 102 | 103 | return data; 104 | } 105 | 106 | public override void UpdateHeader(ref T89ScriptHeader Header) 107 | { 108 | Header.IncludeCount = (byte)Count(); 109 | Header.IncludeTableOffset = GetBaseAddress(); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CBorderedForm.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Refract.UI.Core.Controls 3 | { 4 | partial class CBorderedForm 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Component Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.MainPanel = new System.Windows.Forms.Panel(); 33 | this.TitleBar = new Refract.UI.Core.Controls.CTitleBar(); 34 | this.DesignerContents = new System.Windows.Forms.Panel(); 35 | this.MainPanel.SuspendLayout(); 36 | this.SuspendLayout(); 37 | // 38 | // MainPanel 39 | // 40 | this.MainPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 41 | | System.Windows.Forms.AnchorStyles.Left) 42 | | System.Windows.Forms.AnchorStyles.Right))); 43 | this.MainPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28))))); 44 | this.MainPanel.Controls.Add(this.DesignerContents); 45 | this.MainPanel.Controls.Add(this.TitleBar); 46 | this.MainPanel.Location = new System.Drawing.Point(2, 2); 47 | this.MainPanel.Name = "MainPanel"; 48 | this.MainPanel.Size = new System.Drawing.Size(696, 496); 49 | this.MainPanel.TabIndex = 0; 50 | // 51 | // TitleBar 52 | // 53 | this.TitleBar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(36)))), ((int)(((byte)(36)))), ((int)(((byte)(36))))); 54 | this.TitleBar.Dock = System.Windows.Forms.DockStyle.Top; 55 | this.TitleBar.Location = new System.Drawing.Point(0, 0); 56 | this.TitleBar.Name = "TitleBar"; 57 | this.TitleBar.Size = new System.Drawing.Size(696, 32); 58 | this.TitleBar.TabIndex = 0; 59 | // 60 | // DesignerContents 61 | // 62 | this.DesignerContents.Dock = System.Windows.Forms.DockStyle.Fill; 63 | this.DesignerContents.Location = new System.Drawing.Point(0, 32); 64 | this.DesignerContents.Name = "DesignerContents"; 65 | this.DesignerContents.Size = new System.Drawing.Size(696, 464); 66 | this.DesignerContents.TabIndex = 1; 67 | // 68 | // CBorderedForm 69 | // 70 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 71 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 72 | this.BackColor = System.Drawing.Color.DodgerBlue; 73 | this.Controls.Add(this.MainPanel); 74 | this.Name = "CBorderedForm"; 75 | this.Size = new System.Drawing.Size(700, 500); 76 | this.MainPanel.ResumeLayout(false); 77 | this.ResumeLayout(false); 78 | 79 | } 80 | 81 | #endregion 82 | 83 | private System.Windows.Forms.Panel MainPanel; 84 | private CTitleBar TitleBar; 85 | private System.Windows.Forms.Panel DesignerContents; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Default Project/T8/scripts/main.gsc: -------------------------------------------------------------------------------- 1 | init() 2 | { 3 | //gametype started 4 | 5 | // example of shorthand struct initialization 6 | level.tutorial = 7 | { 8 | #hello: "hello world!", 9 | #var: "Skipped!", 10 | #arrayShorthand: [#"hashkey":"value 1", 1:"value 2", 2:"value 3"], 11 | #arrayVariadic: array("value 1", "value 2", "value 3") 12 | }; 13 | } 14 | 15 | onPlayerConnect() 16 | { 17 | //connected 18 | self thread waitForNotify(); 19 | } 20 | 21 | waitForNotify() 22 | { 23 | self endon(#"disconnect"); 24 | while(true) 25 | { 26 | result = self waittill(#"example notify"); 27 | if(!isdefined(result.action)) continue; 28 | if(result.action == #"killround") 29 | { 30 | level.zombie_total = 0; 31 | foreach(ai in getaiteamarray(level.zombie_team)) ai kill(); 32 | self iprintln(level.tutorial.var); 33 | } 34 | } 35 | } 36 | 37 | onPlayerSpawned() 38 | { 39 | // notice how endon now takes variadic parameters 40 | self endon(#"disconnect", #"spawned_player"); 41 | level endon(#"end_game", #"game_ended"); 42 | self thread InfiniteAmmo(); 43 | self thread ANoclipBind(); 44 | 45 | while(1) 46 | { 47 | if(self adsButtonPressed() && self useButtonPressed()) 48 | { 49 | self notify(#"example notify", {#action:#"killround"}); 50 | while(self useButtonPressed() || self adsButtonPressed()) waitframe(1); 51 | } 52 | 53 | if(self.score < 20000) self.score = 20000; 54 | self freezeControls(false); 55 | self enableInvulnerability(); 56 | 57 | // waits a single frame 58 | waitframe(1); 59 | } 60 | } 61 | 62 | InfiniteAmmo() 63 | { 64 | self endon(#"spawned_player", #"disconnect"); 65 | level endon(#"end_game", #"game_ended"); 66 | while(true) 67 | { 68 | weapon = self GetCurrentWeapon(); 69 | offhand = self GetCurrentOffhand(); 70 | if(!(!isdefined(weapon) || weapon === level.weaponNone || !isdefined(weapon.clipSize) || weapon.clipSize < 1)) 71 | { 72 | self SetWeaponAmmoClip(weapon, 1337); 73 | self givemaxammo(weapon); 74 | self givemaxammo(offhand); 75 | self gadgetpowerset(2, 100); 76 | self gadgetpowerset(1, 100); 77 | self gadgetpowerset(0, 100); 78 | } 79 | if(isdefined(offhand) && offhand !== level.weaponNone) self givemaxammo(offhand); 80 | 81 | // waittill now returns a variable 82 | result = self waittill(#"weapon_fired", #"grenade_fire", #"missile_fire", #"weapon_change", #"melee"); 83 | } 84 | } 85 | 86 | ANoclipBind() 87 | { 88 | self endon(#"spawned_player", #"disconnect", #"bled_out"); 89 | level endon(#"end_game", #"game_ended"); 90 | self notify(#"stop_player_out_of_playable_area_monitor"); 91 | self iprintln("[{+frag}] ^3to ^2Toggle fly mode"); 92 | self unlink(); 93 | if(isdefined(self.originObj)) self.originObj delete(); 94 | while(true) 95 | { 96 | if(self fragbuttonpressed()) 97 | { 98 | self.originObj = spawn("script_origin", self.origin, 1); 99 | self.originObj.angles = self.angles; 100 | self PlayerLinkTo(self.originObj, undefined); 101 | while(self fragbuttonpressed()) waitframe(1); 102 | self iprintln("^2Enabled"); 103 | self iprintln("[{+breath_sprint}] to fly"); 104 | self enableweapons(); 105 | while(true) 106 | { 107 | if(self fragbuttonpressed()) break; 108 | if(self SprintButtonPressed()) 109 | { 110 | normalized = AnglesToForward(self getPlayerAngles()); 111 | scaled = vectorScale(normalized, 60); 112 | originpos = self.origin + scaled; 113 | self.originObj.origin = originpos; 114 | } 115 | waitframe(1); 116 | } 117 | self unlink(); 118 | if(isdefined(self.originObj)) self.originObj delete(); 119 | self iprintln("^1Disabled"); 120 | while(self fragbuttonpressed()) waitframe(1); 121 | } 122 | waitframe(1); 123 | } 124 | } -------------------------------------------------------------------------------- /ExternalTestingUtility/UI/Core/Controls/CTitleBar.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Refract.UI.Core.Controls 3 | { 4 | partial class CTitleBar 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Component Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.TitleLabel = new System.Windows.Forms.Label(); 33 | this.ExitButton = new System.Windows.Forms.Button(); 34 | this.SuspendLayout(); 35 | // 36 | // TitleLabel 37 | // 38 | this.TitleLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 39 | | System.Windows.Forms.AnchorStyles.Left))); 40 | this.TitleLabel.AutoSize = true; 41 | this.TitleLabel.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 42 | this.TitleLabel.ForeColor = System.Drawing.Color.WhiteSmoke; 43 | this.TitleLabel.Location = new System.Drawing.Point(4, 4); 44 | this.TitleLabel.Name = "TitleLabel"; 45 | this.TitleLabel.Size = new System.Drawing.Size(39, 21); 46 | this.TitleLabel.TabIndex = 0; 47 | this.TitleLabel.Text = "Title"; 48 | // 49 | // ExitButton 50 | // 51 | this.ExitButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 52 | | System.Windows.Forms.AnchorStyles.Right))); 53 | this.ExitButton.FlatAppearance.BorderSize = 0; 54 | this.ExitButton.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(50)))), ((int)(((byte)(50))))); 55 | this.ExitButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; 56 | this.ExitButton.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 57 | this.ExitButton.ForeColor = System.Drawing.Color.WhiteSmoke; 58 | this.ExitButton.Location = new System.Drawing.Point(268, 0); 59 | this.ExitButton.Margin = new System.Windows.Forms.Padding(0); 60 | this.ExitButton.Name = "ExitButton"; 61 | this.ExitButton.Size = new System.Drawing.Size(32, 32); 62 | this.ExitButton.TabIndex = 1; 63 | this.ExitButton.Text = "x"; 64 | this.ExitButton.UseVisualStyleBackColor = true; 65 | this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click); 66 | // 67 | // CTitleBar 68 | // 69 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 70 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 71 | this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(36)))), ((int)(((byte)(36)))), ((int)(((byte)(36))))); 72 | this.Controls.Add(this.ExitButton); 73 | this.Controls.Add(this.TitleLabel); 74 | this.Name = "CTitleBar"; 75 | this.Size = new System.Drawing.Size(300, 32); 76 | this.ResumeLayout(false); 77 | this.PerformLayout(); 78 | 79 | } 80 | 81 | #endregion 82 | private System.Windows.Forms.Button ExitButton; 83 | internal System.Windows.Forms.Label TitleLabel; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /t8cinternal/builtins.cpp: -------------------------------------------------------------------------------- 1 | #include "builtins.h" 2 | #include "offsets.h" 3 | #include "detours.h" 4 | 5 | std::unordered_map GSCBuiltins::CustomFunctions; 6 | tScrVm_GetString GSCBuiltins::ScrVm_GetString; 7 | tScrVm_GetInt GSCBuiltins::ScrVm_GetInt; 8 | tScrVm_GetNumParam GSCBuiltins::ScrVm_GetNumParam; 9 | tScrVm_AddInt GSCBuiltins::ScrVm_AddInt; 10 | tScrVm_AddBool GSCBuiltins::ScrVm_AddBool; 11 | 12 | // add all custom builtins here 13 | void GSCBuiltins::Generate() 14 | { 15 | // Compiler related functions // 16 | 17 | // compiler::detour() 18 | // Link and execute detours included in loaded scripts. 19 | AddCustomFunction("detour", GSCBuiltins::GScr_detour); 20 | 21 | // compiler::relinkdetours() 22 | // Re-link any detours that did not get linked previously due to script load order, etc. 23 | AddCustomFunction("relinkdetours", GSCBuiltins::GScr_relinkDetours); 24 | 25 | // General purpose // 26 | 27 | // compiler::livesplit(str_split_name); 28 | // Send a split signal to livesplit through named pipe access. 29 | // : Name of the split to send to livesplit 30 | AddCustomFunction("livesplit", GSCBuiltins::GScr_livesplit); 31 | 32 | // compiler::nprintln(str_message) 33 | // Prints a line of text to an open, untitled notepad window. 34 | // : Text to print 35 | AddCustomFunction("nprintln", GSCBuiltins::GScr_nprintln); 36 | } 37 | 38 | void GSCBuiltins::Init() 39 | { 40 | GSCBuiltins::Generate(); 41 | auto builtinFunction = (BuiltinFunctionDef*)OFF_IsProfileBuild; 42 | builtinFunction->max_args = 255; 43 | builtinFunction->actionFunc = GSCBuiltins::Exec; 44 | 45 | ScrVm_GetString = (tScrVm_GetString)OFF_ScrVm_GetString; 46 | ScrVm_GetInt = (tScrVm_GetInt)OFF_ScrVm_GetInt; 47 | ScrVm_GetNumParam = (tScrVm_GetNumParam)OFF_ScrVm_GetNumParam; 48 | ScrVm_AddInt = (tScrVm_AddInt)OFF_ScrVm_AddInt; 49 | ScrVm_AddBool = (tScrVm_AddBool)OFF_ScrVm_AddBool; 50 | } 51 | 52 | void GSCBuiltins::AddCustomFunction(const char* name, void* funcPtr) 53 | { 54 | CustomFunctions[t8hash(name)] = funcPtr; 55 | } 56 | 57 | INT64 GSCBuiltins::Exec(int scriptInst) 58 | { 59 | auto numParams = ScrVm_GetNumParam(scriptInst); 60 | nlog("called with %d parameters", numParams); // TODO 61 | if (!numParams) 62 | { 63 | return ScrVm_AddBool(scriptInst, 0); 64 | } 65 | 66 | INT32 func = ScrVm_GetInt(scriptInst, 0); 67 | if (CustomFunctions.find(func) == CustomFunctions.end()) 68 | { 69 | // unknown builtin 70 | nlog("unknown builtin %p", func); 71 | return ScrVm_AddBool(scriptInst, 0); 72 | } 73 | 74 | reinterpret_cast(CustomFunctions[func])(scriptInst); 75 | return ScrVm_AddBool(scriptInst, 0); 76 | } 77 | 78 | // START OF BUILTIN DEFINITIONS 79 | 80 | /* 81 | prints a line to an open notepad window 82 | nprintln(whatToPrint); 83 | */ 84 | void GSCBuiltins::GScr_nprintln(int scriptInst) 85 | { 86 | // note: we use 1 as our param index because custom builtin params start at 1. The first param (0) is always the name of the function called. 87 | // we also use %s to prevent a string format vulnerability! 88 | nlog("%s", ScrVm_GetString(0, 1)); 89 | } 90 | 91 | void GSCBuiltins::GScr_detour(int scriptInst) 92 | { 93 | if (scriptInst) 94 | { 95 | return; 96 | } 97 | ScriptDetours::DetoursEnabled = true; 98 | } 99 | 100 | void GSCBuiltins::GScr_relinkDetours(int scriptInst) 101 | { 102 | if (scriptInst) 103 | { 104 | return; 105 | } 106 | ScriptDetours::LinkDetours(); 107 | } 108 | 109 | void GSCBuiltins::GScr_livesplit(int scriptInst) 110 | { 111 | if (scriptInst) 112 | { 113 | return; 114 | } 115 | 116 | HANDLE livesplit = CreateFile("\\\\.\\pipe\\LiveSplit", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); 117 | if (!livesplit) 118 | { 119 | return; 120 | } 121 | 122 | const char* message = ScrVm_GetString(0, 1); 123 | WriteFile(livesplit, message, strlen(message), nullptr, NULL); 124 | CloseHandle(livesplit); 125 | } 126 | 127 | 128 | void GSCBuiltins::nlog(const char* str, ...) 129 | { 130 | va_list ap; 131 | HWND notepad, edit; 132 | char buf[256]; 133 | 134 | va_start(ap, str); 135 | vsprintf(buf, str, ap); 136 | va_end(ap); 137 | strcat_s(buf, 256, "\r\n"); 138 | notepad = FindWindow(NULL, "Untitled - Notepad"); 139 | if (!notepad) 140 | { 141 | notepad = FindWindow(NULL, "*Untitled - Notepad"); 142 | } 143 | edit = FindWindowEx(notepad, NULL, "EDIT", NULL); 144 | SendMessage(edit, EM_REPLACESEL, TRUE, (LPARAM)buf); 145 | } -------------------------------------------------------------------------------- /External/PointerEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace System 9 | { 10 | public struct PointerEx 11 | { 12 | public IntPtr IntPtr { get; set; } 13 | public PointerEx(IntPtr value) 14 | { 15 | IntPtr = value; 16 | } 17 | 18 | #region overrides 19 | public static implicit operator IntPtr(PointerEx px) 20 | { 21 | return px.IntPtr; 22 | } 23 | 24 | public static implicit operator PointerEx(IntPtr ip) 25 | { 26 | return new PointerEx(ip); 27 | } 28 | 29 | public static PointerEx operator +(PointerEx px, PointerEx pxo) 30 | { 31 | return px.Add(pxo); 32 | } 33 | 34 | public static PointerEx operator -(PointerEx px, PointerEx pxo) 35 | { 36 | return px.Subtract(pxo); 37 | } 38 | 39 | public static PointerEx operator &(PointerEx px, PointerEx pxo) 40 | { 41 | return IntPtr.Size == sizeof(int) ? ((int)px & (int)pxo) : ((long)px & (long)pxo); 42 | } 43 | 44 | public static bool operator ==(PointerEx px, PointerEx pxo) 45 | { 46 | return px.IntPtr == pxo.IntPtr; 47 | } 48 | 49 | public static bool operator !=(PointerEx px, PointerEx pxo) 50 | { 51 | return px.IntPtr != pxo.IntPtr; 52 | } 53 | 54 | public override int GetHashCode() 55 | { 56 | return this; 57 | } 58 | 59 | public override bool Equals(object o) 60 | { 61 | if(o is PointerEx px) 62 | { 63 | return px == this; 64 | } 65 | return false; 66 | } 67 | 68 | public static implicit operator bool(PointerEx px) 69 | { 70 | return (long)px != 0; 71 | } 72 | 73 | public static implicit operator byte(PointerEx px) 74 | { 75 | return (byte)px.IntPtr; 76 | } 77 | 78 | public static implicit operator sbyte(PointerEx px) 79 | { 80 | return (sbyte)px.IntPtr; 81 | } 82 | 83 | public static implicit operator int(PointerEx px) 84 | { 85 | return (int)px.IntPtr.ToInt64(); 86 | } 87 | 88 | public static implicit operator uint(PointerEx px) 89 | { 90 | return (uint)px.IntPtr.ToInt64(); 91 | } 92 | 93 | public static implicit operator long(PointerEx px) 94 | { 95 | return px.IntPtr.ToInt64(); 96 | } 97 | 98 | public static implicit operator ulong(PointerEx px) 99 | { 100 | return (ulong)px.IntPtr.ToInt64(); 101 | } 102 | 103 | public static implicit operator PointerEx(int i) 104 | { 105 | return new IntPtr(i); 106 | } 107 | 108 | public static implicit operator PointerEx(uint ui) 109 | { 110 | return new IntPtr((int)ui); 111 | } 112 | 113 | public static implicit operator PointerEx(long l) 114 | { 115 | return new IntPtr(l); 116 | } 117 | 118 | public static implicit operator PointerEx(ulong ul) 119 | { 120 | return new IntPtr((long)ul); 121 | } 122 | 123 | public static bool operator true(PointerEx p) 124 | { 125 | return p; 126 | } 127 | 128 | public static bool operator false(PointerEx p) 129 | { 130 | return !p; 131 | } 132 | 133 | public override string ToString() 134 | { 135 | return IntPtr.ToInt64().ToString($"X{IntPtr.Size * 2}"); 136 | } 137 | 138 | public PointerEx Clone() 139 | { 140 | return new PointerEx(IntPtr); 141 | } 142 | #endregion 143 | } 144 | 145 | /// 146 | /// A dummy type to signal that no return deserialization is needed for a call. 147 | /// 148 | public struct VOID 149 | { 150 | #pragma warning disable CS0169 151 | [Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Placeholder value to initialize struct size")] 152 | private PointerEx __value; 153 | #pragma warning restore CS0169 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /External/PEStructures/PEResourceDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection.PortableExecutable; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using System.Threading.Tasks; 10 | using System.Xml.Linq; 11 | 12 | namespace System.PEStructures 13 | { 14 | public class PEResourceDirectory : PEDataDirectory 15 | { 16 | private const int ManifestResourceId = 0x18; 17 | private const int DllManifestId = 0x2; 18 | public PEResourceDirectory(PEHeaders headers, Memory imageData) : base(headers, imageData, headers.PEHeader.ResourceTableDirectory) { } 19 | 20 | public XDocument GetManifest() 21 | { 22 | if (!IsValid) return null; 23 | 24 | // Read the resource directory 25 | var resourceDirectory = MemoryMarshal.Read(ImageData.Span.Slice(DirectoryOffset)); 26 | var resourceCount = resourceDirectory.NumberOfIdEntries + resourceDirectory.NumberOfNameEntries; 27 | for (var resourceIndex = 0; resourceIndex < resourceCount; resourceIndex++) 28 | { 29 | // Read the first level resource entry 30 | var firstLevelResourceEntryOffset = DirectoryOffset + Unsafe.SizeOf() + Unsafe.SizeOf() * resourceIndex; 31 | var firstLevelResourceEntry = MemoryMarshal.Read(ImageData.Span.Slice(firstLevelResourceEntryOffset)); 32 | if (firstLevelResourceEntry.Id != ManifestResourceId) continue; 33 | 34 | // Read the second level resource entry 35 | var secondLevelResourceEntryOffset = DirectoryOffset + Unsafe.SizeOf() + (firstLevelResourceEntry.lpData & int.MaxValue); 36 | var secondLevelResourceEntry = MemoryMarshal.Read(ImageData.Span.Slice(secondLevelResourceEntryOffset)); 37 | if (secondLevelResourceEntry.Id != DllManifestId) continue; 38 | 39 | // Read the third level resource entry 40 | var thirdLevelResourceEntryOffset = DirectoryOffset + Unsafe.SizeOf() + (secondLevelResourceEntry.lpData & int.MaxValue); 41 | var thirdLevelResourceEntry = MemoryMarshal.Read(ImageData.Span.Slice(thirdLevelResourceEntryOffset)); 42 | 43 | // Read the manifest data entry 44 | var manifestDataEntryOffset = DirectoryOffset + thirdLevelResourceEntry.lpData; 45 | var manifestDataEntry = MemoryMarshal.Read(ImageData.Span.Slice(manifestDataEntryOffset)); 46 | 47 | // Read the manifest 48 | var manifestOffset = RelativeToOffset(manifestDataEntry.lpData); 49 | var manifest = Encoding.UTF8.GetString(ImageData.Span.Slice(manifestOffset, manifestDataEntry.Size).ToArray()); 50 | 51 | // Sanitise the manifest to ensure it can be parsed correctly 52 | manifest = Regex.Replace(manifest, @"\""\""([\d\w\.]*)\""\""", @"""$1"""); 53 | manifest = Regex.Replace(manifest, @"^\s+$[\r\n]*", string.Empty, RegexOptions.Multiline); 54 | manifest = manifest.Replace("SXS_ASSEMBLY_NAME", @""""""); 55 | manifest = manifest.Replace("SXS_ASSEMBLY_VERSION", @""""""); 56 | manifest = manifest.Replace("SXS_PROCESSOR_ARCHITECTURE", @""""""); 57 | return XDocument.Parse(manifest); 58 | } 59 | return null; 60 | } 61 | } 62 | 63 | [StructLayout(LayoutKind.Explicit, Size = 16)] 64 | public readonly struct PEImageResourceDirectory 65 | { 66 | [FieldOffset(0xC)] 67 | public readonly short NumberOfNameEntries; 68 | 69 | [FieldOffset(0xE)] 70 | public readonly short NumberOfIdEntries; 71 | } 72 | 73 | [StructLayout(LayoutKind.Explicit, Size = 8)] 74 | public readonly struct PEImageResourceDirectoryEntry 75 | { 76 | [FieldOffset(0x0)] 77 | public readonly int Id; 78 | 79 | [FieldOffset(0x4)] 80 | public readonly int lpData; 81 | } 82 | 83 | [StructLayout(LayoutKind.Explicit, Size = 16)] 84 | public readonly struct PEImageResourceDataEntry 85 | { 86 | [FieldOffset(0x0)] 87 | public readonly int lpData; 88 | 89 | [FieldOffset(0x4)] 90 | public readonly int Size; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /T7CompilerLib/Utility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace T7CompilerLib 9 | { 10 | /// 11 | /// Utility Functions 12 | /// 13 | internal static class Utility 14 | { 15 | /// 16 | /// Computes the number of bytes require to pad this value 17 | /// 18 | public static int ComputePadding(int value, int alignment) => (((value) + ((alignment) - 1)) & ~((alignment) - 1)) - value; 19 | 20 | /// 21 | /// Aligns the value to the given alignment 22 | /// 23 | public static int AlignValue(this int value, int alignment) => (((value) + ((alignment) - 1)) & ~((alignment) - 1)); 24 | 25 | public static uint AlignValue(this uint value, uint alignment) => (((value) + ((alignment) - 1)) & ~((alignment) - 1)); 26 | 27 | /// 28 | /// Determines if a context value meets a desired value 29 | /// 30 | /// 31 | /// 32 | /// 33 | public static bool HasContext(this uint context, ScriptContext desired) 34 | { 35 | return (context & (uint)desired) > 0; 36 | } 37 | public static byte[] GetBytes(this T input, EndianType Endianess) 38 | { 39 | byte[] data = new byte[0]; 40 | if (input is bool) data = BitConverter.GetBytes((bool)(object)input); 41 | else if (input is char) data = BitConverter.GetBytes((char)(object)input); 42 | else if (input is double) data = BitConverter.GetBytes((double)(object)input); 43 | else if (input is float) data = BitConverter.GetBytes((float)(object)input); 44 | else if (input is int) data = BitConverter.GetBytes((int)(object)input); 45 | else if (input is long) data = BitConverter.GetBytes((long)(object)input); 46 | else if (input is short) data = BitConverter.GetBytes((short)(object)input); 47 | else if (input is uint) data = BitConverter.GetBytes((uint)(object)input); 48 | else if (input is ulong) data = BitConverter.GetBytes((ulong)(object)input); 49 | else data = BitConverter.GetBytes((ushort)(object)input); 50 | 51 | if (Endianess == EndianType.BigEndian) 52 | return data.Reverse().ToArray(); 53 | 54 | return data; 55 | } 56 | 57 | /// 58 | /// Reads a string terminated by a null byte and returns the reader to the original position 59 | /// 60 | /// Read String 61 | public static string PeekNullTerminatedString(this BinaryReader br, long offset, int maxSize = -1) 62 | { 63 | // Create String Builder 64 | StringBuilder str = new StringBuilder(); 65 | // Seek to position 66 | var temp = br.BaseStream.Position; 67 | br.BaseStream.Position = offset; 68 | // Current Byte Read 69 | int byteRead; 70 | // Size of String 71 | int size = 0; 72 | // Loop Until we hit terminating null character 73 | while ((byteRead = br.BaseStream.ReadByte()) != 0x0 && size++ != maxSize) 74 | str.Append(Convert.ToChar(byteRead)); 75 | // Go back 76 | br.BaseStream.Position = temp; 77 | // Ship back Result 78 | return str.ToString(); 79 | } 80 | 81 | /// 82 | /// Writes a null terminated string 83 | /// 84 | /// 85 | /// 86 | public static void WriteNullTerminatedString(this BinaryWriter br, string str) 87 | { 88 | foreach (byte c in Encoding.ASCII.GetBytes(str)) 89 | br.Write(c); 90 | br.Write((byte)0); 91 | } 92 | 93 | /// 94 | /// Counts the number of lines in the given string 95 | /// 96 | public static int GetLineCount(string str) 97 | { 98 | int index = -1; 99 | int count = 0; 100 | while ((index = str.IndexOf(Environment.NewLine, index + 1)) != -1) 101 | count++; 102 | return count + 1; 103 | } 104 | 105 | public static string SanitiseString(string value) => value.Replace("/", "\\").Replace("\b", "\\b"); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /T8CompilerLib/OpCodes/T89OP_GetNumericValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | //should be done 4 | namespace T89CompilerLib.OpCodes 5 | { 6 | public sealed class T89OP_GetNumericValue : T89OpCode 7 | { 8 | protected override ScriptOpCode Code 9 | { 10 | get; set; 11 | } 12 | 13 | private object __value__; 14 | public object Value 15 | { 16 | get 17 | { 18 | return __value__; 19 | } 20 | set 21 | { 22 | Code = GetTypeOfValue(value); 23 | 24 | if(Code == ScriptOpCode.Invalid) 25 | throw new ArgumentException("A non-numeric argument was passed to a numeric opcode!"); 26 | 27 | __value__ = value; 28 | } 29 | } 30 | public T89OP_GetNumericValue(object value) 31 | { 32 | Value = value; 33 | } 34 | 35 | protected override byte[] Serialize(ushort EmissionValue) 36 | { 37 | byte[] data = new byte[GetSize()]; 38 | 39 | base.Serialize(EmissionValue).CopyTo(data, 0); 40 | 41 | if (Code == ScriptOpCode.GetZero) 42 | return data; 43 | 44 | uint DataAddress = GetCommitDataAddress() - CommitAddress; 45 | 46 | switch (ScriptOpMetadata.OpInfo[(int)Code].OperandType) 47 | { 48 | case ScriptOperandType.UInt32: 49 | case ScriptOperandType.Int32: 50 | try { BitConverter.GetBytes(uint.Parse(Value.ToString().Replace("-", ""))).CopyTo(data, DataAddress); } // this is a hack due to new opcodes in t8 51 | catch { BitConverter.GetBytes(int.Parse(Value.ToString())).CopyTo(data, DataAddress); } 52 | break; 53 | case ScriptOperandType.Float: 54 | BitConverter.GetBytes(float.Parse(Value.ToString())).CopyTo(data, DataAddress); 55 | break; 56 | default: 57 | BitConverter.GetBytes(ushort.Parse(Value.ToString().Replace("-", ""))).CopyTo(data, DataAddress); 58 | break; 59 | } 60 | 61 | return data; 62 | } 63 | 64 | public override uint GetCommitDataAddress() 65 | { 66 | switch(ScriptOpMetadata.OpInfo[(int)Code].OperandType) 67 | { 68 | case ScriptOperandType.UInt32: 69 | case ScriptOperandType.Int32: 70 | case ScriptOperandType.Float: 71 | return (CommitAddress + T89OP_SIZE).AlignValue(0x4); 72 | default: 73 | return (CommitAddress + T89OP_SIZE); 74 | } 75 | } 76 | 77 | public override uint GetSize() 78 | { 79 | return (GetCommitDataAddress() - CommitAddress) + GetValueSize(); 80 | } 81 | 82 | public byte GetValueSize() 83 | { 84 | switch (ScriptOpMetadata.OpInfo[(int)Code].OperandType) 85 | { 86 | case ScriptOperandType.UInt32: 87 | case ScriptOperandType.Int32: 88 | case ScriptOperandType.Float: 89 | return 4; 90 | case ScriptOperandType.None: 91 | return 0; 92 | default: 93 | return 2; 94 | } 95 | } 96 | 97 | private static ScriptOpCode GetTypeOfValue(object value) 98 | { 99 | if (value is double || value is float) 100 | return ScriptOpCode.GetFloat; 101 | 102 | long unknown; 103 | 104 | try { unknown = long.Parse(value.ToString()); } 105 | catch (Exception e){ Console.WriteLine(e.ToString()); return ScriptOpCode.Invalid; } 106 | 107 | if (unknown == 0) 108 | return ScriptOpCode.GetZero; 109 | 110 | if(unknown > 0) 111 | { 112 | if (unknown <= 255) 113 | return ScriptOpCode.GetByte; 114 | 115 | if (unknown <= 65535) 116 | return ScriptOpCode.GetUnsignedShort; 117 | } 118 | else 119 | { 120 | if (unknown >= -255) 121 | return ScriptOpCode.GetNegByte; 122 | 123 | if (unknown >= -65535) 124 | return ScriptOpCode.GetNegUnsignedShort; 125 | } 126 | 127 | return unknown > 0 ? ScriptOpCode.GetUnsignedInteger : ScriptOpCode.GetNegUnsignedInteger; 128 | } 129 | 130 | public override string ToString() 131 | { 132 | return Value.ToString(); 133 | } 134 | } 135 | } 136 | --------------------------------------------------------------------------------