-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathxr_strings.pas
117 lines (90 loc) · 2.12 KB
/
xr_strings.pas
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
unit xr_strings;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
type
str_value = packed record
dwReference:cardinal;
length:cardinal;
dwCRC:cardinal;
next:pointer;
value:char; //really array here
end;
pstr_value = ^str_value;
shared_str = packed record
p_:pstr_value;
end;
pshared_str = ^shared_str;
str_container=packed record
//TODO:Fill
end;
pstr_container=^str_container;
ppstr_container=^pstr_container;
string_path=array [0..519] of Char;
procedure init_string(str:pshared_str); stdcall;
procedure assign_string(str:pshared_str; text:PChar); stdcall;
procedure assign_string_noaddref(str:pshared_str; text:PChar); stdcall; //'Hacky' version, try don't use
function get_string_value(str:pshared_str):PAnsiChar; stdcall;
function Init():boolean; stdcall;
function str_container_dock(str:PChar):pstr_value; stdcall;
implementation
uses basegamedata;
procedure assign_string_noaddref(str:pshared_str; text:PChar); stdcall;
begin
assign_string(str, text);
if (str^.p_<>nil) then begin
str^.p_.dwReference:=str^.p_.dwReference-1;
end;
end;
procedure assign_string(str:pshared_str; text:PChar); stdcall;
var
docked:pstr_value;
begin
docked:= str_container_dock(text);
if docked<>nil then begin
docked.dwReference:=docked.dwReference+1;
end;
if (str^.p_<>nil) then begin
str^.p_.dwReference:=str^.p_.dwReference-1;
if str^.p_.dwReference=0 then str.p_:=nil
end;
str^.p_:=docked;
end;
procedure init_string(str:pshared_str); stdcall;
begin
str.p_:=nil;
end;
function get_string_value(str:pshared_str):PAnsiChar; stdcall;
begin
result:='';
if str=nil then exit;
if str.p_=nil then exit;
result:=PAnsiChar(@str.p_.value);
end;
function GetStrContainer():pointer;stdcall;
begin
asm
mov eax, xrgame_addr
mov eax, [eax+$512814]
mov eax, [eax]
mov @result, eax
end;
end;
function str_container_dock(str:PChar):pstr_value; stdcall;
asm
pushad
pushfd
push str
call GetStrContainer
mov ecx, eax
mov eax, xrcore_addr
add eax, $20690
call eax
mov @Result, eax
popfd
popad
end;
function Init():boolean; stdcall;
begin
result:=true;
end;
end.