Skip to content

Commit

Permalink
Allow CLimate as param type in standard compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
llde committed Nov 16, 2024
1 parent 4988c0d commit edb29dd
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 14 deletions.
4 changes: 4 additions & 0 deletions obse/obse/CommandTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3014,13 +3014,15 @@ void CommandTable::Init(void)
g_scriptCommands.Add(&kCommandInfo_SetOwningFactionRequiredRank);
g_scriptCommands.Add(&kCommandInfo_SetParentCellOwningFactionRequiredRank);
ADD_CMD_RET(GetLoadedTypeArray, kRetnType_Array);
//OBSE 22.9
g_scriptCommands.Add(&kCommandInfo_GetEditorID2, kRetnType_String);

UInt32 opcodeGetDisease = g_scriptCommands.GetByName("GetDisease")->opcode;
CommandInfo newgetDisease = kCommandInfo_IsDiseased;
newgetDisease.shortName = "GetDisease";
newgetDisease.longName = "GetDisease";
g_scriptCommands.Replace(opcodeGetDisease, &newgetDisease); //Ready for the mapping
//OBSE 22.10
ADD_CMD(sv_PrintBytes);
/* to add later if problems can be solved
g_scriptCommands.Add(&kCommandInfo_SetCurrentClimate); // too many problems
Expand Down Expand Up @@ -3337,6 +3339,7 @@ const char* SimpleStringForParamType(UInt32 paramType)
case kParamType_Owner: return "ref";
case kParamType_EffectShader: return "ref";
case kParamType_Birthsign: return "ref";
case kParamType_Climate: return "ref";
default: return "<unknown>";
}
}
Expand Down Expand Up @@ -3382,6 +3385,7 @@ const char* StringForParamType(UInt32 paramType)
case kParamType_Owner: return "Owner";
case kParamType_EffectShader: return "EffectShader";
case kParamType_Birthsign: return "Birthsign";
case kParamType_Climate: return "Climate";
default: return "<unknown>";
}
}
Expand Down
3 changes: 2 additions & 1 deletion obse/obse/CommandTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ enum ParamType
kParamType_Owner = 0x24, // IsOwner TESForm *, kFormType_NPC or kFormType_Faction
kParamType_EffectShader = 0x25, // haven't seen used TESForm *, kFormType_EffectShader

// custom OBSE types
// custom OBSE types or extensions for vanilla compiler
kParamType_StringVar = 0x01,
kParamType_Array = 0x26, // only usable with compiler override; StandardCompile() will report unrecognized param type
kParamType_Climate = 0x27
};

/*** IsInventoryObjectType types
Expand Down
2 changes: 1 addition & 1 deletion obse/obse/Commands_String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ DEFINE_COMMAND(sv_SubString,

static ParamInfo kParams_sv_ToNumeric[2] =
{
{ "stringVar", kParamType_Integer, 0 },
{ "stringVar", kParamType_StringVar, 0 },
{ "startPos", kParamType_Integer, 1 },
};

Expand Down
30 changes: 18 additions & 12 deletions obse/obse/Commands_Weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static bool SetClimateValue_Execute(COMMAND_ARGS, UInt32 whichVal)
ExtractArgsEx(paramInfo, arg1, opcodeOffsetPtr, scriptObj, eventList, &intVal, &form);
TESClimate* climate = (TESClimate*)Oblivion_DynamicCast(form, 0, RTTI_TESForm, RTTI_TESClimate, 0);
if (!climate) return true;

Console_Print("CLimate %08X %s", climate->refID, climate->GetEditorName());
UInt8 nuVal = (UInt8)intVal;

switch (whichVal) {
Expand Down Expand Up @@ -792,6 +792,12 @@ CommandInfo kCommandInfo_GetWeatherInfo =
0
};

static ParamInfo kParams_OneClimateType[] =
{
{ "climate", kParamType_Climate, 0 },
};


CommandInfo kCommandInfo_GetClimateSunriseBegin =
{
"GetClimateSunriseBegin",
Expand All @@ -800,7 +806,7 @@ CommandInfo kCommandInfo_GetClimateSunriseBegin =
"returns the sunrise begin time for the specified climate",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateSunriseBegin_Execute),
Cmd_Default_Parse,
NULL,
Expand All @@ -815,7 +821,7 @@ CommandInfo kCommandInfo_GetClimateSunriseEnd =
"returns the sunrise end time for the specified climate",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateSunriseEnd_Execute),
Cmd_Default_Parse,
NULL,
Expand All @@ -830,7 +836,7 @@ CommandInfo kCommandInfo_GetClimateSunsetBegin =
"returns the sunset begin time for the specified climate",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateSunsetBegin_Execute),
Cmd_Default_Parse,
NULL,
Expand All @@ -845,7 +851,7 @@ CommandInfo kCommandInfo_GetClimateSunsetEnd =
"returns the sunset end time for the specified climate",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateSunsetEnd_Execute),
Cmd_Default_Parse,
NULL,
Expand All @@ -860,7 +866,7 @@ CommandInfo kCommandInfo_GetClimateMoonPhaseLength =
"returns the length of the moon phase",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateMoonPhaseLength_Execute),
Cmd_Default_Parse,
NULL,
Expand All @@ -875,7 +881,7 @@ CommandInfo kCommandInfo_GetClimateHasMasser =
"returns 1 if the specified climate shows Masser",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateHasMasser_Execute),
Cmd_Default_Parse,
NULL,
Expand All @@ -890,17 +896,17 @@ CommandInfo kCommandInfo_GetClimateHasSecunda =
"returns 1 if the specified climate shows Secunda",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateHasSecunda_Execute),
Cmd_Default_Parse,
NULL,
0
};

static ParamInfo kParams_SetClimateInteger[2] =
static ParamInfo kParams_SetClimateInteger[] =
{
{ "value", kParamType_Integer, 0 },
{ "weather", kParamType_WeatherID, 0 },
{ "climate", kParamType_Climate, 0 },
};

CommandInfo kCommandInfo_SetClimateSunriseBegin =
Expand Down Expand Up @@ -1016,7 +1022,7 @@ CommandInfo kCommandInfo_GetClimateVolatility =
"returns the climate's volatility",
0,
2,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_GetClimateVolatility_Execute),
Cmd_Default_Parse,
NULL,
Expand Down Expand Up @@ -1498,7 +1504,7 @@ CommandInfo kCommandInfo_SetCurrentClimate =
"sets the current climate to the passed value",
0,
1,
kParams_OneWeatherType,
kParams_OneClimateType,
HANDLER(Cmd_SetCurrentClimate_Execute),
Cmd_Default_Parse,
NULL,
Expand Down
2 changes: 2 additions & 0 deletions obse/obse/ExpressionEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ bool ExpressionEvaluator::ConvertDefaultArg(ScriptToken* arg, ParamInfo* info, b
typeToMatch = kFormType_NPC; break;
case kParamType_EffectShader:
typeToMatch = kFormType_EffectShader; break;
case kParamType_Climate:
typeToMatch = kFormType_Climate; break;
}

if (form->typeID == typeToMatch) {
Expand Down
1 change: 1 addition & 0 deletions obse/obse/GameAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ static bool v_ExtractArgsEx(SInt16 numArgs, ParamInfo * paramInfo, UInt8* &scrip
case kParamType_NPC:
case kParamType_Owner:
case kParamType_EffectShader:
case kParamType_Climate:
{
TESForm ** out = va_arg(args, TESForm **);
TESForm* form = ResolveForm(scriptData, scriptObj, eventList);
Expand Down
52 changes: 52 additions & 0 deletions obse/obse/Hooks_Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ static const UInt32 kExpressionParserBufferOverflowRetnAddr_2 = 0x004F986A;
static const UInt32 kWarnForDeprecatedCommandsHook = 0x00503119;
static const UInt32 kWarnForDeprecatedCommandsReturn = 0x0050311E;

static const UInt32 kDefaultCompilerHook = 0x00501F4E;
static const UInt32 kDefaultCompilerRetn = 0x00501F5C;

static __declspec(naked) void ExpressionParserBufferOverflowHook_1(void)
{
Expand Down Expand Up @@ -746,6 +748,55 @@ static __declspec(naked) void __cdecl WarnForDeprecatedCommands(void){
}
}

static const UInt32 kReportScriptError = 0x004FFF40;
static const UInt32 kDefaultCompilerCompileFormsArg = 0x00501A1A;
static char kErrorCLimate[] = "Invalid Climate '%s' for parameter %s.\r\nCompiled script not saved!";
static __declspec(naked) void __cdecl HandleCustomTypes(void) {
__asm {
cmp ecx, 0x27
jne error

push eax
mov eax, [esp + 244h - 8h]
test eax,eax
jz error1
cmp byte ptr[eax + 4], 2Eh; //TESCLimate
jnz error1
pop eax
jmp [kDefaultCompilerCompileFormsArg]
error:
push ebx
mov ebx, [esp + 244h - 228h]
push ecx
push 94A1B0h //offset aParamTypeDRefe
push ebx
call kReportScriptError
add esp, 0xC
pop ebx
jmp[kDefaultCompilerRetn]
error1:
pop eax
push ebx
movsx ebx, word ptr[esp + 244h - 230h]
push edx
mov edx, [esp + 248h - 22Ch]
lea ebx, [ebx + ebx * 2]
mov ebx, [edx + ebx * 4]
pop edx
push ebx
lea ebx, [esp + 248h - 218h]
push ebx
lea ebx, kErrorCLimate
push ebx
mov ebx, [esp + 250h - 228h]
push ebx
call kReportScriptError
add esp, 0x10
pop ebx
jmp[kDefaultCompilerRetn]

}
}

void Hook_Compiler_Init()
{
Expand All @@ -760,6 +811,7 @@ void Hook_Compiler_Init()
// hook code in the vanilla expression parser's subroutine to fix the buffer overflow
WriteRelJump(kExpressionParserBufferOverflowHookAddr_1, (UInt32)&ExpressionParserBufferOverflowHook_1);
WriteRelJump(kExpressionParserBufferOverflowHookAddr_2, (UInt32)&ExpressionParserBufferOverflowHook_2);
WriteRelJump(kDefaultCompilerHook, (UInt32)&HandleCustomTypes);

CompilerOverride::InitHooks();
}
Expand Down

0 comments on commit edb29dd

Please sign in to comment.