Repository navigation
Expand file tree
/
Copy pathwpp-add-build.sh
More file actions
219 lines (184 loc) · 8.09 KB
/
Copy pathwpp-add-build.sh
File metadata and controls
219 lines (184 loc) · 8.09 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
# Add a new WoW client build to WowPacketParser's version switch statements.
#
# Usage:
# ./wpp-add-build.sh <build_number>
#
# Example:
# ./wpp-add-build.sh 66192
#
# This script edits 4 files in the WPP source tree:
# 1. ClientVersionBuild.cs — enum value (V12_0_1_NNNNN = NNNNN)
# 2. Opcodes.cs — GetOpcodeDefiningBuild() switch
# 3. UpdateFields.cs — GetUpdateFieldDictionaryBuildName() switch
# 4. ClientVersion.cs — build-date mapping + GetVersionDefiningBuild() switch
#
# Each has a block of `case ClientVersionBuild.V12_0_1_NNNNN:` entries
# before a return statement. The script inserts the new build case
# before the return line if not already present.
#
# After editing, it rebuilds WPP with `dotnet build` and copies output.
set -euo pipefail
# ── Configuration ────────────────────────────────────────────────────
WPP_ROOT="C:/Tools/WowPacketParser"
WPP_SLN="$WPP_ROOT/WowPacketParser.sln"
WPP_OUT="$WPP_ROOT/out"
OPCODES="$WPP_ROOT/WowPacketParser/Enums/Version/Opcodes.cs"
UPDATEFIELDS="$WPP_ROOT/WowPacketParser/Enums/Version/UpdateFields.cs"
CLIENTVERSION="$WPP_ROOT/WowPacketParser/Misc/ClientVersion.cs"
# The 12.x expansion prefix for the enum
VERSION_PREFIX="V12_0_1"
# ─────────────────────────────────────────────────────────────────────
if [ $# -ne 1 ]; then
echo "Usage: $0 <build_number>"
echo "Example: $0 66192"
exit 1
fi
BUILD="$1"
# Validate build number is numeric
if ! [[ "$BUILD" =~ ^[0-9]+$ ]]; then
echo "Error: Build number must be numeric, got '$BUILD'"
exit 1
fi
ENUM_NAME="${VERSION_PREFIX}_${BUILD}"
CASE_LINE=" case ClientVersionBuild.${ENUM_NAME}:"
echo "=========================================="
echo " WPP Build Adder"
echo " Build: $BUILD"
echo " Enum: ClientVersionBuild.$ENUM_NAME"
echo "=========================================="
echo ""
# ── Step 0: Add enum value to ClientVersionBuild.cs ──────────────────
ENUM_FILE="$WPP_ROOT/WowPacketParser/Enums/ClientVersionBuild.cs"
ENUM_LINE=" ${ENUM_NAME} = ${BUILD},"
if grep -q "$ENUM_NAME" "$ENUM_FILE"; then
echo " ClientVersionBuild.cs: Enum already present — skipped."
else
# Find the last V12_0_1_* enum line and insert after it
last_enum_line=$(grep -n "${VERSION_PREFIX}_[0-9]* = [0-9]*," "$ENUM_FILE" | tail -1 | cut -d: -f1)
if [ -n "$last_enum_line" ]; then
sed -i "${last_enum_line}a\\${ENUM_LINE}" "$ENUM_FILE"
echo " ClientVersionBuild.cs: Added enum value after line $last_enum_line."
else
echo " ClientVersionBuild.cs: No ${VERSION_PREFIX}_* enum entries found — MANUAL EDIT NEEDED."
fi
fi
# ── Step 0b: Add build-date mapping to ClientVersion.cs ──────────────
# The date array maps builds to release dates (used for auto-detection).
# Use today's date since we don't know the exact release date.
TODAY_Y=$(date +%Y)
TODAY_M=$(date +%-m) # no leading zero
TODAY_D=$(date +%-d) # no leading zero
DATE_LINE=" new KeyValuePair<ClientVersionBuild, DateTime>(ClientVersionBuild.${ENUM_NAME}, new DateTime(${TODAY_Y}, ${TODAY_M:=1}, ${TODAY_D:=1})),"
if grep -q "ClientVersionBuild.${ENUM_NAME}.*DateTime" "$CLIENTVERSION"; then
echo " ClientVersion.cs (date mapping): Already present — skipped."
else
# Find the last V12_0_1_* DateTime line
last_date_line=$(grep -n "ClientVersionBuild\.${VERSION_PREFIX}_.*DateTime" "$CLIENTVERSION" | tail -1 | cut -d: -f1)
if [ -n "$last_date_line" ]; then
sed -i "${last_date_line}a\\${DATE_LINE}" "$CLIENTVERSION"
echo " ClientVersion.cs (date mapping): Added after line $last_date_line."
else
echo " ClientVersion.cs (date mapping): No ${VERSION_PREFIX}_* date entries found — MANUAL EDIT NEEDED."
fi
fi
# ── Insert into each file ────────────────────────────────────────────
# Strategy: Find the FIRST contiguous group of V12_0_1_* case lines in the file.
# This is always the defining-build switch (GetOpcodeDefiningBuild,
# GetUpdateFieldDictionaryBuildName, or GetVersionDefiningBuild).
# Any second group (e.g. GetOpcodeDictionary) uses the defining build enum only.
insert_build_case() {
local file="$1"
local func_name="$2"
local basename
basename=$(basename "$file")
# Get all V12_0_1_ case line numbers
local line_nums
line_nums=$(grep -n "case ClientVersionBuild\.${VERSION_PREFIX}_" "$file" | cut -d: -f1)
if [ -z "$line_nums" ]; then
echo " $basename ($func_name): No V12_0_1_* cases found — SKIPPED (manual edit needed)."
return 1
fi
# Find the last line of the FIRST contiguous group.
# Lines are contiguous if each is within 1 of the previous.
local prev=""
local first_group_end=""
for ln in $line_nums; do
if [ -z "$prev" ]; then
prev=$ln
first_group_end=$ln
continue
fi
local gap=$((ln - prev))
if [ "$gap" -le 2 ]; then
# Still in the same contiguous group (allow gap of 2 for blank lines)
first_group_end=$ln
prev=$ln
else
# Hit a gap — we've found the end of the first group
break
fi
done
# Check if our build is already in this first group
local first_line
first_line=$(echo "$line_nums" | head -1)
if sed -n "${first_line},${first_group_end}p" "$file" | grep -q "$ENUM_NAME"; then
echo " $basename ($func_name): Already present — skipped."
return 0
fi
# Insert our case line after the last line of the first group
sed -i "${first_group_end}a\\${CASE_LINE}" "$file"
echo " $basename ($func_name): Inserted after line $first_group_end."
return 0
}
changes=0
# File 1: Opcodes.cs — GetOpcodeDefiningBuild()
echo "Processing files..."
if insert_build_case "$OPCODES" "GetOpcodeDefiningBuild"; then
changes=$((changes + 1))
fi
# File 2: UpdateFields.cs — GetUpdateFieldDictionaryBuildName()
if insert_build_case "$UPDATEFIELDS" "GetUpdateFieldDictionaryBuildName"; then
changes=$((changes + 1))
fi
# File 3: ClientVersion.cs — GetVersionDefiningBuild()
if insert_build_case "$CLIENTVERSION" "GetVersionDefiningBuild"; then
changes=$((changes + 1))
fi
echo ""
# ── Rebuild WPP ──────────────────────────────────────────────────────
if grep -q "$ENUM_NAME" "$ENUM_FILE" && grep -q "$ENUM_NAME" "$OPCODES" && grep -q "$ENUM_NAME" "$UPDATEFIELDS" && grep -q "$ENUM_NAME" "$CLIENTVERSION"; then
echo "All 4 files have $ENUM_NAME."
else
echo "!! Some files are missing $ENUM_NAME — check output above."
fi
echo ""
echo "=========================================="
echo " Rebuilding WPP..."
echo "=========================================="
cd "$WPP_ROOT"
dotnet build "$WPP_SLN" --configuration Release --verbosity minimal 2>&1
BUILD_EXIT=$?
if [ $BUILD_EXIT -ne 0 ]; then
echo ""
echo "!! Build FAILED (exit code $BUILD_EXIT)"
echo " Check errors above. You may need to add $ENUM_NAME to ClientVersionBuild.cs first."
exit 1
fi
echo ""
echo "=========================================="
echo " Copying build output..."
echo "=========================================="
# Copy the built DLLs to the out/ directory
RELEASE_DIR="$WPP_ROOT/WowPacketParser/bin/Release"
# WPP may output to a net* subfolder or directly to bin/Release/
NET_DIR=$(find "$RELEASE_DIR" -maxdepth 1 -name "net*" -type d 2>/dev/null | sort | tail -1)
SRC_DIR="${NET_DIR:-$RELEASE_DIR}"
if [ -d "$SRC_DIR" ]; then
cp -r "$SRC_DIR"/* "$WPP_OUT/" 2>/dev/null
echo " Copied from $SRC_DIR -> out/"
else
echo " Could not find build output. Check $RELEASE_DIR manually."
fi
echo ""
echo "Done. WPP is ready to parse build $BUILD packets."