From 57d7aa1e221b7365c952f741d5ca751c5d2666f7 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Tue, 9 Jan 2024 23:53:36 +0800 Subject: [PATCH] [saco] Update scriping.cpp/.h * Implements ExecuteScriptBuf * Implements InitScripting * Adds ScriptCommand stub --- saco/game/game.h | 1 + saco/game/scripting.cpp | 38 ++++++++++++++++++++++++++++++++++++++ saco/game/scripting.h | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/saco/game/game.h b/saco/game/game.h index 3b0e59d..1940118 100644 --- a/saco/game/game.h +++ b/saco/game/game.h @@ -4,6 +4,7 @@ #include "address.h" #include "audio.h" #include "camera.h" +#include "scripting.h" //----------------------------------------------------------- diff --git a/saco/game/scripting.cpp b/saco/game/scripting.cpp index da57d12..5cf888d 100644 --- a/saco/game/scripting.cpp +++ b/saco/game/scripting.cpp @@ -1,5 +1,43 @@ #include "../main.h" +GAME_SCRIPT_THREAD* gst; +FARPROC ProcessOneCommand = (FARPROC)0x469EB0; +BYTE ScriptBuf[255]; + DWORD dwScmOpcodeDebug=0; BOOL bScmLocalDebug=FALSE; + +int __declspec(naked) ExecuteScriptBuf() +{ + __asm + { + mov bScmLocalDebug, 1; + + mov eax, OFFSET ScriptBuf // Move our script buffer base into eax. + + mov ecx, gst // Move GAME_SCRIPT_THREAD structure into ecx. + mov [ecx+0x14], eax // Move eax into the gst->dwScriptIP. + + call ProcessOneCommand // Call the game's script opcode processor. + + mov ecx, gst // Move game script thread into ecx again. + mov eax, [ecx+0xC5] // Move the dwIfFlag into eax (return value). + + mov bScmLocalDebug, 0; + + ret // return. + } +} + +int ScriptCommand(const SCRIPT_COMMAND* pScriptCommand, ...) +{ + // TODO: ScriptCommand + return 0; +} + +void InitScripting() +{ + gst = new GAME_SCRIPT_THREAD; + ZeroMemory(gst, sizeof(GAME_SCRIPT_THREAD)); +} diff --git a/saco/game/scripting.h b/saco/game/scripting.h index e69de29..33ec209 100644 --- a/saco/game/scripting.h +++ b/saco/game/scripting.h @@ -0,0 +1,19 @@ + +#pragma once + +#define MAX_SCRIPT_VARS 16 // Size of our variable saving array + +// Super Simplified SA Version +struct GAME_SCRIPT_THREAD // 0xE0 bytes total. +{ + BYTE _gap0[224]; +}; + +struct SCRIPT_COMMAND // Params +{ // i = integer + WORD OpCode; // f = float + char Params[MAX_SCRIPT_VARS]; // v = variable +}; // s = string + + +